y-server-plugin-mock

0.0.8 • Public • Published

y-server-plugin-mock

y-server-plugin-mock is a y-server plugin to mock data.

Install

npm install y-server-plugin-mock

Usage

const path = require('path');

const yServer = require('y-server');
const mockPlugin = require('y-server-plugin-mock');

yServer({
  plugins: [
    mockPlugin({
      mockEnable: true,
      mockDir: path.join(__dirname, './json'), // 模拟数据根目录
      mockAdapter: require('./json/adapter.js'),
      mockPaths: ['/api/*'],
    }),
    (app) => {
      app.get('/', (req, res, next) => {
        res.getMockData('/api/foo').then(data => res.send(data)).catch(next);
      });
    },
  ],
});

Notes

  • mockDir is the base directory of mock data.
  • mockAdapter is the adapter of mock data.

License

MIT License

/y-server-plugin-mock/

    Package Sidebar

    Install

    npm i y-server-plugin-mock

    Weekly Downloads

    5

    Version

    0.0.8

    License

    MIT

    Last publish

    Collaborators

    • smadey