Javascript webpack dev服务器代理将请求发布到本地.json文件
我手头有一个新项目,所以我没有任何服务器端支持,它们还没有准备好 我想用本地json文件模拟我的http请求 我有两个正在进行的请求: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
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')
结果:
proxyTable: {
'/entity':{
target: 'http://localhost:8080/mock/',
pathRewrite(path, option) {
option.method = 'GET';
return url.parse(path).pathname + '.json';
}
}