【发布时间】:2014-10-30 18:52:17
【问题描述】:
我在前端有一个节点代理和角度。 如果节点代理未运行,有没有办法可以始终重定向到(服务器关闭!对不起!)的角度页面?我不想让人们在没有节点代理的情况下看到其他更安全的页面。
我正在考虑使用 HTTP 状态,但是有什么简单的方法吗?
谢谢!
【问题讨论】:
标签: javascript angularjs node.js proxy
我在前端有一个节点代理和角度。 如果节点代理未运行,有没有办法可以始终重定向到(服务器关闭!对不起!)的角度页面?我不想让人们在没有节点代理的情况下看到其他更安全的页面。
我正在考虑使用 HTTP 状态,但是有什么简单的方法吗?
谢谢!
【问题讨论】:
标签: javascript angularjs node.js proxy
$http interceptors 可以在全球范围内为您做到这一点
使用拦截器,您可以查看每个请求的响应。我建议使用 HTTP 状态,特别是 503 "Service Unavailable"(服务器当前不可用(因为它超载或停机维护)。一般来说,这是一个临时状态。)
$httpProvider.interceptors.push(function($location) {
var handleResponse = function(response) {
if(response.status === 503){
$location.path('/503.html'); // not sure if you are using ui-router or how your routing is set up...
}else{
return response;
}
};
return {
'response': handleResponse,
'responseError': handleResponse,
};
});
【讨论】:
$location 旁边注入$state,然后您可以执行$state.go(...)。 stateProvider 用于设置状态,$state.go() 用于转换到状态。