JSON-Server All In One
JSON-Server All In One
const AutoLaunchMockServer = () => {
// mock server startup
var db = require('./mock/db.js');
var jsonServer = require('json-server');
var server = jsonServer.create();
var router = jsonServer.router(db);
var middlewares = jsonServer.defaults();
server.use(middlewares);
server.use('/mock', router);
server.listen(9098, () => {
console.log('Mock API Server is running!');
});
}
// webpack proxy
{
devServer: {
hot: true,
contentBase: './src',
historyApiFallback: true,
noInfo: true,
host: devServerHost,
port: devServerPort,
publicPath: '/',
proxy: [
{
context: [
'/user/api/',
'/qywx/',
],
target: 'http://dev.xgqfrms.xyz',
changeOrigin: true,
onError (err) {
console.log('proxy error:', err);
},
},
{
context: ['/mock/'],
target: 'http://localhost:9098',
changeOrigin: true,
}
],
clientLogLevel: 'warning',
overlay: { warnings: false, errors: true },
watchOptions: { poll: false }
},
}
refs
https://dev-preview.cnblogs.com/xgqfrms/p/14308267.html
https://github.com/xyz-data/json/issues/1
https://github.com/typicode/json-server/issues/513
https://github.com/xgqfrms-GitHub/json-server#可选择端口
https://github.com/xyz-data/redux-seeds/issues/13
https://github.com/coryhouse/react-slingshot/blob/master/docs/FAQ.md
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14630101.html
未经授权禁止转载,违者必究!