最近,我被安排到一个团队中。作为一名新生,我需要熟悉项目代码。该项目使用Angular2和Spring Boot。它还使用Webpack捆绑资产,包括代理(使用Webpack Dev Server)。由于应用程序的规模,代理用于连接到各种后端服务器。
代理人在那里,我的队友和#39;电脑似乎运行得很好。不幸的是,我的电脑似乎没有阅读代理。这是代理文件(http://在每个代理目标之前。我的声誉不允许我发布两个以上的链接):
devServer: {
proxy:
{
'/node': {
target: 'localhost:8080/',
pathRewrite: {'^/node' : ''},
secure: false
},
'/apiv1': {
target: 'localhost:8080/', //[dev]8080
pathRewrite: {'^/apiv1' : ''},
secure: false
},
'/apiv2': {
target: 'localhost:8081/',
pathRewrite: {'^/apiv2' : ''},
secure: false
},
'/apiv3': {
target: 'localhost:8082/',
pathRewrite: {'^/apiv3' : ''},
secure: false
},
'/apiv4': {
target: 'localhost:8083/',
pathRewrite: {'^/apiv4' : ''},
secure: false
},
'/apiv5': {
target: 'localhost:7080/',
pathRewrite: {'^/apiv5' : ''},
secure: false
}
,
'/apiv6': {
target: 'localhost:8084/',
pathRewrite: {'^/apiv6' : ''},
secure: false
},
'/apiv7': {
// target: 'localhost:8081/', // local
target: 'http://localhost:8085/',
pathRewrite: {'^/apiv7' : ''},
secure: false
},
'/apiv8': {
target: 'localhost:8086/',
pathRewrite: {'^/apiv8' : ''},
secure: false
}
},
historyApiFallback: true,
stats: 'minimal'
}
不幸的是,无论何时尝试访问API URL(例如,' localhost:8050 / apiv8 / service / 012997JX / accounts'),我都会收到404错误:
Request URL: http://localhost:8050/apiv8/service/012997JE/accounts
Request Method: GET
Status Code: 404 Not Found
Remote Address: 127.0.0.1:8050
Referrer Policy: no-referrer-when-downgrade
但是,我知道这不是后端的错。我已经尝试访问&localhost:8086 / service / 012997JE / accounts'并且它返回了我想要的对象。此外,当运行npm start时,代理似乎没有构建:
> btpn-fes@1.0.0 start C:\IT170517\fes-service-maintenance-sample\frontend
> webpack-dev-server --inline --progress --port 8050
70% 4/4 build modules
http://localhost:8050/
webpack result is served from http://localhost:8050/
content is served from C:\IT170517\fes-service-maintenance-sample\frontend
404s will fallback to /index.html
chunk {0} app.js (app) 1.72 MB {3} [rendered]
chunk {1} env.js (env) 153 bytes {2} [rendered]
chunk {2} polyfills.js (polyfills) 475 kB [rendered]
chunk {3} vendor.js, vendor.css (vendor) 4.47 MB {1} [rendered]
Child html-webpack-plugin for "index.html":
chunk {0} index.html 806 bytes [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 360 kB [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 10.2 kB [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 81.3 kB [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 43.1 kB [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 46.9 kB [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 439 kB [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 30.7 kB [rendered]
webpack: Compiled successfully.
如果您想知道,我正在运行以下网络包:
我的代理配置有问题吗?
感谢您的帮助。
答案 0 :(得分:0)
好吧,我终于通过升级到另一个Webpack版本解决了这个问题。我现在使用以下Webpack配置:
"webpack": "1.15.0",
"webpack-dev-server": "1.16.5",
"webpack-merge": "0.14.1"
将我的nodeJS版本降级为6.10.3 LTS。
希望这有帮助。