gpt4 book ai didi

javascript - 如果 NODE 代理未运行,则阻止渲染 ANGULAR 页面

转载 作者:太空宇宙 更新时间:2023-11-04 01:01:13 26 4
gpt4 key购买 nike

我在前端有一个 Node 代理和 Angular 。如果 Node 代理未运行,有没有一种方法可以让我始终重定向到(服务器关闭!抱歉!)的 Angular 页面?我不想让人们在没有 Node 代理的情况下看到其他更安全的页面。

我正在考虑使用 HTTP 状态,但是有一些简单的方法吗?

谢谢!

最佳答案

$http interceptors可以在全局范围内为您做到这一点

使用拦截器,您可以查看每个请求的响应。我建议使用 HTTP 状态,特别是 503“服务不可用”(服务器当前不可用(因为过载或停机维护)。通常,这是一个临时状态。)

$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,
};
});

关于javascript - 如果 NODE 代理未运行,则阻止渲染 ANGULAR 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26661099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com