Webpack 开发服务器代理 Returns 404
Webpack Dev Server Proxy Returns 404
最近,我被分到了一个团队。作为大一新生,需要熟悉项目代码。该项目使用 Angular2 和 Spring Boot。它还使用 Webpack 来捆绑资产,包括代理(使用 Webpack Dev Server)。由于应用程序的规模,代理用于连接各种后端服务器。
有代理,我队友的电脑好像运行就好了。不幸的是,我的电脑似乎无法读取代理。这是代理文件(http:// 在每个代理目标之前。我的声誉不允许我 post 超过两个链接):
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”,它返回了我想要的对象。另外,当 运行ning 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.
如果您想知道,我正在 运行安装以下 webpack:
- 网络包:1.13.0
- webpack-开发服务器:1.14.1
- webpack-合并:0.14.0
我的代理配置有问题吗?
感谢您的帮助。
好吧,我终于通过升级到另一个 Webpack 版本解决了这个问题。我现在使用以下 Webpack 配置:
"webpack": "1.15.0",
"webpack-dev-server": "1.16.5",
"webpack-merge": "0.14.1"
同时将我的 nodeJS 版本降级到 6.10.3 LTS。
希望对您有所帮助。
最近,我被分到了一个团队。作为大一新生,需要熟悉项目代码。该项目使用 Angular2 和 Spring Boot。它还使用 Webpack 来捆绑资产,包括代理(使用 Webpack Dev Server)。由于应用程序的规模,代理用于连接各种后端服务器。
有代理,我队友的电脑好像运行就好了。不幸的是,我的电脑似乎无法读取代理。这是代理文件(http:// 在每个代理目标之前。我的声誉不允许我 post 超过两个链接):
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”,它返回了我想要的对象。另外,当 运行ning 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.
如果您想知道,我正在 运行安装以下 webpack:
- 网络包:1.13.0
- webpack-开发服务器:1.14.1
- webpack-合并:0.14.0
我的代理配置有问题吗?
感谢您的帮助。
好吧,我终于通过升级到另一个 Webpack 版本解决了这个问题。我现在使用以下 Webpack 配置:
"webpack": "1.15.0",
"webpack-dev-server": "1.16.5",
"webpack-merge": "0.14.1"
同时将我的 nodeJS 版本降级到 6.10.3 LTS。
希望对您有所帮助。