Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gitaaron/node-simulator
When API testing slows your front-end development down: record and replay HTTP responses like a boss
https://github.com/gitaaron/node-simulator
Last synced: about 2 months ago
JSON representation
When API testing slows your front-end development down: record and replay HTTP responses like a boss
- Host: GitHub
- URL: https://github.com/gitaaron/node-simulator
- Owner: gitaaron
- License: mit
- Created: 2013-11-01T18:43:52.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-19T20:06:16.000Z (over 10 years ago)
- Last Synced: 2024-04-14T15:04:45.264Z (9 months ago)
- Language: JavaScript
- Size: 152 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-simulator
### When APIs slow your front-end development down: record and replay HTTP responses like a boss.
## Overview
A showcase of how to use three other node modules:
* replay (slightly forked)
* express
* http-proxyProviding a way to stub out a back-end by simply running node-replay in record mode and invoking the requests that your application does or will do in the future.
## Setup
```
npm install git+https://github.com/genesyslab/node-simulator.git
```## How to use
Create a server.js for all your static content (html/css/javascript etc..)
```
var express = require('simulator').express;var app = express();
app.use(express.static(__dirname +'/public'));app.listen(process.env.PORT || 3000);
```
Set up http-proxy to forward all api requests to your actual server.
```
var httpProxy = require('simulator').httpProxyapp.all('/api/*', function(req, res) {
var proxy = new httpProxy.HttpProxy({target:{host:[YOUR_BACKEND_HOST], port:[YOUR_BACKEND_PORT]});
proxy.proxyRequest(req, res);
});```
Run in record mode to start saving responses from the server. Invoke all requests that you would like to be stubbed out.
```
REPLAY=record node server
```Now run your stubbed out server.
```
node server
```You will notice it is not longer making any requests directly to your backend. Instead, the fixtures are loaded.