When deploying our app we use app_offline.htm
to tell IIS to make our application unavailable. If there are any clients that have the Angular app loaded already, what I would like to do is intercept any requests to the server while the app is offline and then reload the page so that app_offline.htm
displays instead of the Angular app.
I thought it would be as simple as putting <!--Offline-->
or something at the top of app_offline.htm
and then have an http interceptor that checks if any response starts with that, but I never seem to get the content of app_offline.htm
in a response. Amazingly, I'm still getting app content in the responses. I'm wondering if maybe it's pulling a cached version of the content or something. If I manually reload the page, I do get the app_offline.htm
page as expected.
So how can I detect if the server is unavailable and reload the page?
UPDATE
So this appears to maybe be more of an IIS configuration issue than anything. The app_offline.htm
file appears to only affect resources managed by ASP.NET. From this answer, I learned that you can configure ASP.NET MVC to handle all requests using this following code:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
This has the effect of preventing static content like HTML from being served even if app_offline.htm
exists, but it also appears to continue firing the 'response' handler of the Angular http interceptor with undefined
as the response instead of firing the 'responseError' handler with an object having a status of 503 Service Unavailable. I'm hesitant to use this solution because I don't know if there are other conditions that may cause an undefined
response, but so far it appears to be working:
function appOfflineHttpInterceptor($window, $q) {
return {
'response': function (response) {
if (typeof response == "undefined")
$window.location.reload();
return response || $q.when(response);
}
};
}
Does anyone know if there are other conditions that would cause an undefined response - which would render this solution nonviable?