Angular CLI 代理服务器将响应 404 更改为 200
Angular CLI proxy server changing response 404 to 200
我已启用 Angular/CLI 代理来代理我对休息服务器(端口 9000 上的 PlayFramework)的请求。我正在使用
启动我的代理服务器
ng serve --open --proxy-config src/proxy.conf.js --host 0.0.0.0
这是配置
const PROXY_CONFIG = {
"**": {
"target": "http://localhost:9000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"bypass": function (req) {
if (req.headers.accept.indexOf("html") !== -1) {
console.log("Skipping proxy for browser request.");
return "/index.html";
}
}
}
};
module.exports = PROXY_CONFIG;
我无法从 Play 服务器获得 404 响应,而是我不断获得未知路由的 OK 200。获取 404 很重要,因为如果用户无权获取某些路由,PlayServer 会以 404 响应。使用 Postman 时看起来像这样
当 运行
http://localhost:9000/api/secured
我得到 404,没关系
当 运行
http://localhost:4200/api/secured
我得到 200,它服务于家庭路线
好的,我想通了,我的错。我的安全特征中有这个
private def onUnauthorized(request: RequestHeader) = Results.Redirect(routes.FrontendController.index())
/**
* Action for authenticated users.
*/
def IsAuthenticated(f: => User => Request[AnyContent] => Result) = Security.Authenticated(username , onUnauthorized) { username =>
那是在做重定向:(
我已启用 Angular/CLI 代理来代理我对休息服务器(端口 9000 上的 PlayFramework)的请求。我正在使用
启动我的代理服务器ng serve --open --proxy-config src/proxy.conf.js --host 0.0.0.0
这是配置
const PROXY_CONFIG = {
"**": {
"target": "http://localhost:9000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"bypass": function (req) {
if (req.headers.accept.indexOf("html") !== -1) {
console.log("Skipping proxy for browser request.");
return "/index.html";
}
}
}
};
module.exports = PROXY_CONFIG;
我无法从 Play 服务器获得 404 响应,而是我不断获得未知路由的 OK 200。获取 404 很重要,因为如果用户无权获取某些路由,PlayServer 会以 404 响应。使用 Postman 时看起来像这样 当 运行
http://localhost:9000/api/secured
我得到 404,没关系
当 运行
http://localhost:4200/api/secured
我得到 200,它服务于家庭路线
好的,我想通了,我的错。我的安全特征中有这个
private def onUnauthorized(request: RequestHeader) = Results.Redirect(routes.FrontendController.index())
/**
* Action for authenticated users.
*/
def IsAuthenticated(f: => User => Request[AnyContent] => Result) = Security.Authenticated(username , onUnauthorized) { username =>
那是在做重定向:(