Javascript webpack dev服务器代理将请求发布到本地.json文件

Javascript webpack dev服务器代理将请求发布到本地.json文件,javascript,webpack-dev-server,Javascript,Webpack Dev Server,我手头有一个新项目,所以我没有任何服务器端支持,它们还没有准备好 我想用本地json文件模拟我的http请求 我有两个正在进行的请求: /实体/获取方法为“获取” /实体/创建方法为“POST” 我有两个本地json文件 mock/entity/get.json mock/entity/create.json 在我的配置文件中: config/index.js: proxyTable: { '/entity':{ target: 'http://localhost:8080/mock

我手头有一个新项目,所以我没有任何服务器端支持,它们还没有准备好

我想用本地json文件模拟我的http请求

我有两个正在进行的请求:

  • /实体/获取方法为“获取”

  • /实体/创建方法为“POST”

  • 我有两个本地json文件

  • mock/entity/get.json

  • mock/entity/create.json

  • 在我的配置文件中:

    config/index.js:

    proxyTable: {
    
    '/entity':{
    
        target: 'http://localhost:8080/mock/',
    
        pathRewrite(path, option) {
    
            option.method = 'GET';
    
            return url.parse(path).pathname + '.json';
    
        }
    
    }
    
    代理表:{

    '/entity':{
    
        target: 'http://localhost:8080/mock/',
    
        pathRewrite(path) {
    
            return url.parse(path).pathname + '.json';
    
        }
    
    }
    
    }

    build/dev-server.js

    app.use('/mock',express.static('mock')

    结果:

  • /实体/得到,我得到我想要的

  • /实体/创建,404

  • 我的问题:

  • 为什么express服务器不能响应create.json

  • 在webpack1.0中,我有同样的问题,但我通过将所有post请求转换为get请求来处理这个问题,其副作用是,在post-get转换过程中,我丢失了所有请求参数。我可以接受它,但在Webpack2.0中,我甚至不知道如何这样配置

  • 问题2已解决:

    config/index.js:

    proxyTable: {
    
    '/entity':{
    
        target: 'http://localhost:8080/mock/',
    
        pathRewrite(path, option) {
    
            option.method = 'GET';
    
            return url.parse(path).pathname + '.json';
    
        }
    
    }