我在前端有一个节点代理和角度。 有没有办法,如果节点代理没有运行,我总是可以重定向到(服务器关闭!抱歉!)的角度页面?我不想让人们在没有节点代理的情况下看到其他更安全的页面。
我在考虑使用HTTP状态,但有一些简单的方法吗?
谢谢!
答案 0 :(得分:1)
$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,
};
});