【发布时间】:2017-03-03 12:23:06
【问题描述】:
我克隆了一个 angular2-webpack-starter 项目,它运行良好;现在我想为这个项目添加一个单独的 NodeJS 服务器(我需要用 NodeJS 模拟一些数据作为后端),但不知道如何以及从哪里开始,有人可以帮忙吗?
【问题讨论】:
我克隆了一个 angular2-webpack-starter 项目,它运行良好;现在我想为这个项目添加一个单独的 NodeJS 服务器(我需要用 NodeJS 模拟一些数据作为后端),但不知道如何以及从哪里开始,有人可以帮忙吗?
【问题讨论】:
这个问题已经解决,只需要在config/webpack.dev.js中配置devServer的代理即可:
module.exports = {
entry:{...},
...
devServer: {
host: 'localhost',
port: 8086, //frontend port
historyApiFallback: true,
noInfo: true,
watchOptions: {
aggregateTimeout: 300,
poll: 100
},
outputPath: '/',
proxy: {
'/api/*': { //backend url prefix, some thing like '/api/users/:userId'
target: 'http://localhost:3000', // backend host and port
secure: false
}
}
}
};
【讨论】: