我正在使用Angular 2 Webpack . 我正在使用localhost:8000 / app提供我的应用程序 . 我想为我的api Build 一个代理服务器,这样他们就不会从localhost服务,而是从网址提供服务 . 通过参考https://webpack.github.io/docs/webpack-dev-server.html上的解决方案,它什么都不做 . 我对代理的webpack配置是:

devServer: {
        port: 8000,
        historyApiFallback: {
            index: '/app'
        },
        quiet: false,
        stats: { colors: true },
        headers: {
            'Access-Control-Allow-Origin': '*',
        },
        setup: function(app) {
            app.use('/app/assets', express.static(path.join(__dirname, 'assets')));
        },

    proxy: {
            "/appApi": {
            "target": {
                "host": "somewebsite.com",
                "protocol": 'http:',
                "port": 80
            },
            ignorePath: true,
            changeOrigin: true,
            secure: false
            }
        }

    }

我的角度要求是:

this.http.get('appApi/getData', 
              headers
              ).subscribe(res => {console.log(res)});

在查看请求时,appApi / getData仍然可以从以下位置获得:

本地主机:8000 /应用/ appApi /的getData

我期待代理工作,终点是:

http://somewebsite.com/appApi/getData