JSPM

@bigorange/mock-server

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q31131F
  • License MIT

a very simple mock server of nodeJs

Package Exports

  • @bigorange/mock-server

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@bigorange/mock-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mockServer

a very simple mock server of nodeJs.

it will search the response content exported by the file named *.mock.js in ./mock, you can change this behavior by pass a option.

Installing

npm install @bigorange/mock-server

Example

response content

Note the mock folder and server file should be in the same level.

// ./mock/data.mock.js
module.exports = {
    "GET /api/mock/test": {
        "state": "SUCCESS",
        data: true
    },
}

start a mock server directly

const server = require('@bigorange/mock-server');
server.boostrap();

use it as a express middleware

const express = require('express');
const mockServer = require('@bigorange/mock-server');
const app = express();
const port = 4000;

app.use(express.json());
app.use(mockServer.createMiddleware(app));

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
});

add mock feature if you are already use express

const express = require('express');
const mockServer = require('@bigorange/mock-server');
const app = express();
const port = 5000;

mockServer.attachMock(app); // now your express have the mock feature

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
});

option

server.boostrap(option);
app.use(mockServer.createMiddleware(app, option));
mockServer.attachMock(app, option);

option: {
    port: number, // the server listening port, be invalid in createMiddleware and attachMock
    searchPath: string, // the search path of response content, default './mock'
    matchRegExp: RegExp, // the suffix of file export response content, default '.mock.js'
}