2014-10-30 62 views
1

我在前端有一个节点代理和角度。 如果节点代理没有运行,是否有一种方法可以随时重定向到服务器的角度页面(对不起!)!如果没有节点代理,我不想让人们看到其他更安全的页面。如果NODE代理没有运行,防止呈现ANGULAR页面

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

谢谢!

回答

1

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

酷!从文档看来,它必须存在于服务中。 可以在app.module中的.run()函数中工作吗? – dkengaroo 2014-10-30 21:32:16

+0

因为我使用的是stateProvider,我是否应该让intercepter环绕我的所有状态,以便在每个状态下进行检查? 用于离) $ httpProvider.interceptors.push(函数($位置){ VAR用handleResponse =函数(响应){ stateprovider.state() }; 返回{ '响应':用handleResponse, 'responseError' :handleResponse, }; }); – dkengaroo 2014-10-30 22:09:35

+0

使用$注射器! – dkengaroo 2014-10-30 22:19:06

相关问题