xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-04-07 23:06  xgqfrms  阅读(89)  评论(6编辑  收藏  举报