NodeJS http request handling middleware with admin UI.
Is your back-end api not ready, too slow, or unstable? You don't have to wait for that by mocking all back-end responses using http-request-middleware.
Compatible with connect, express, browser-sync and many more.
Add the middleware to your code before you start the server.
var express = require('express');
var httpRequestMiddleware = require('http-request-middleware');
var app = express();
app.use(httpRequestMidleware.middlewares);
app.listen(3000);$ npm install --save-dev http-request-middleware{
"/api/foo": {
"responses": [
{"name": "case 1", "url": "api-responses/foo.json", "active": true},
{"name": "case 2", "url": "api-responses/foo2.json"},
{"name": "case 3", "url": "api-responses/foo3.json"}
]
},
"/api/bar": {
"responses": [
{"name": "case 1", "url": "api-responses/bar.json", "active": true},
{"name": "case 2", "url": "api-responses/bar2.json"},
{"name": "case 3", "url": "api-responses/bar3.json"}
]
}
}
[
{
"active":true,
"context": [
"api/foo"
],
"options": {
"logLevel": "debug",
"target": "https://www.yourServer.com",
"secure": false,
"autoRewrite": true,
"changeOrigin": true
}
}
]
proxy-url options can be found here
{
"name": "my package",
"version": "0.1.0",
...
httpRequestMiddleware: {
"basePath": "./dist",
"customUrls": "./custom-urls.json",
"proxyUrls": "./proxy-urls.json
}
}
var browserSync = require('browser-sync');
var httpRequestMiddleware = require('http-request-middleware');
browserSync.init({
logLevel: 'debug',
host: 'localhost.rogers.com', // e.g. localhost.mysite.com
port: 3000,
startPath: '/',
ui: { port: 3001 },
open: 'external',
browser: 'default',
server: {
baseDir: __dirname,
middleware: httpRequestMiddleware.middlewares
},
https: true
});
https://localhost:3000/developer.html
{
"name": "eclipse",
"version": "0.2.7",
...
"httpRequestMiddleware": {
"basePath": "builds/dist",
"customUrls": "gulp-tasks/browser-sync/custom-urls.json",
"proxyUrls": "gulp-tasks/browser-sync/proxy-urls.json",
"headUrls": [
"https://fonts.googleapis.com/icon?family=Material+Icons",
"https://unpkg.com/font-awesome@4.7.0/css/font-awesome.css",
"https://unpkg.com/mce/dist/themes/blue.css",
"https://unpkg.com/mce/dist/mce.min.css",
"https://unpkg.com/mce/dist/mce.min.js"
],
"navigationlinks": [
"<mce-nav-item href='https://example.com/my-document' icon='fa-book'>Documents</mce-nav-item>",
"<mce-nav-item href='/web/consumer/developer' icon='link'>Links</mce-nav-item>"
]
}
}
| Option | Description |
|---|---|
| basePath | the base path that .json files are located. e.g. 'builds/dist' |
| customUrls | the file path of custom urls configuration file .g. './custom-urls.json' |
| proxyUrls | Optional, the file path of proxy urls configuration file .g. './proxy-urls.json' |
| headUrls | Optional, the list of HTML header files |
| navigationLinks | list of html links to be seen on the side bar of admin UI. |
http-request-middleware is compatible with the following servers:
- connect
- express
- browser-sync
- lite-server
- grunt-contrib-connect
- grunt-browser-sync
- gulp-connect
- gulp-webserver
- webpack-dev-server
The MIT License (MIT)
Copyright (c) 2018 Allen Kim
