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.