如何为angular2-webpack-starter设置webpack-dev-server的代理?

时间:2017-02-03 00:34:35

标签: angular webpack-dev-server starter-kits

我一直在将angular1项目移植到angular2-webpack-starter项目中。前端部分工作得很好,我试图通过在webpack.dev.js文件中设置代理来将前端连接到后端服务器:

...
devServer: {
  proxy: {
    '/auth/*': {
      target: 'http://localhost:9000/auth/',
      secure: false
    }
  },
  port: METADATA.port,
  host: METADATA.host,
  historyApiFallback: true,
  watchOptions: {
    aggregateTimeout: 300,
    poll: 1000
  }
},
...

有些东西显然是错误的:http://localhost:3000/auth/local不代理到后端。所以你的帮助将不胜感激。或者是webpack-dev-server的代理内容还没有工作???

谢谢!

1 个答案:

答案 0 :(得分:0)

devServer: {
      port: METADATA.port,
      host: METADATA.host,
      historyApiFallback: true,
      proxy: {
        "/api": "http://localhost:3100"
      },
      watchOptions: {
        aggregateTimeout: 300,
        poll: 1000
      }
    }