2014-10-30 30 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