http-dev-server

0.2.3 • Public • Published

http-dev-server

A simple http server for develop purpose, support rewrite request, mock response data and serve static resources.

Install

Install on global path

npm install -g http-dev-server   

Or install as a development dependency

npm install --save-dev http-dev-server   

Usage

Run server by global command

http-dev-server -f config-sample.js

Or config npm script and run server by npm (for example: {"server": "http-dev-server -f ./dev-server-config.js}")

npm run server

Config Sample

the content of config-sample.js

module.exports = {
    hostname: '0.0.0.0',
    port: '3000',
    webPath: __dirname,
    mockPath: __dirname,
    logLevel: 'debug',
    proxies: {
        '/api': {
            host: 'api.examples.com',
        },
        '/userapi': {
            host: '127.0.0.1:7000',
            headers: {
                host: 'api.examples.com'
            }
        }
    },
    mocks: {
        '/api/item/list': 'testdata/test.json',
        '/api/item/1': function(req, res) {
            res.json({ code: 0, data: { id: 1, name: "javascript in action" } });
        },
        '/api/cart': {
            'get': 'testdata/test.json',
            'post': function(req, res) {
                res.send("add cart successful");
            }
        }
    }
};

Test

Run project test using mocha

npm run test   

Refs

Package Sidebar

Install

npm i http-dev-server

Weekly Downloads

6

Version

0.2.3

License

MIT

Last publish

Collaborators

  • bruceman