It is very much possible, using a http interceptor. Here's an example:
https://github.com/dlidstrom/MinaGlosor/blob/master/MinaGlosor.Web/wwwroot/app/httpInterceptor.js
(function () {
'use strict';
angular.module('mgApp').factory('CustomHttpInterceptor', HttpInterceptor);
HttpInterceptor.$inject = ['$q', '$rootScope', 'toaster', 'AppVersion'];
function HttpInterceptor($q, $rootScope, toaster, appVersion) {
var needUpgradeWarned = false;
var interceptor = {
request: function (config) {
config.url += '?' + 'v=' + appVersion;
return config;
},
responseError: function (rejection) {
if (rejection.status == 426 && !needUpgradeWarned) {
toaster.pop('error', "Uppdatering krävs",
rejection.data.message, 30000);
needUpgradeWarned = true;
$rootScope.upgradeRequired = true;
}
return $q.reject(rejection);
}
};
return interceptor;
}
})();
Register with your module:
https://github.com/dlidstrom/MinaGlosor/blob/master/MinaGlosor.Web/wwwroot/app/app.js
(function () {
'use strict';
var appVersion = $('meta[name="appVersion"]').attr('content');
angular.module('mgApp', ['ngRoute', 'ngMessages',
'toaster']).config(Config).value('AppVersion', appVersion);
Config.$inject = ['$httpProvider'];
function Config($httpProvider) {
$httpProvider.interceptors.push('CustomHttpInterceptor');
}
})();
And add the necessary markup:
https://github.com/dlidstrom/MinaGlosor/blob/master/MinaGlosor.Web/Views/Shared/LoggedIn.cshtml
<div class="container ng-cloak">
<div class="row" ng-show="upgradeRequired">
<div class="col-xs-12">
<span class="label label-danger">Uppgradering krävs.
Vänligen ladda om sidan.</span>
</div>
</div>
<div ng-view></div>
</div>
Now you need to enable this in your backend technology. I'm using ASP.NET
WebAPI and there it looks like this:
https://github.com/dlidstrom/MinaGlosor/blob/master/MinaGlosor.Web/Infrastructure/Attributes/CheckAppVersionAttribute.cs
public class CheckAppVersionAttribute : ActionFilterAttribute
{
public override void
OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var nvp =
actionContext.Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x =>
x.Value);
if (nvp.ContainsKey("v") && nvp["v"] != Application.GetAppVersion())
{
actionContext.Response =
actionContext.Request.CreateErrorResponse(
HttpStatusCode.UpgradeRequired,
"Det finns en nyare version, vänligen ladda om sidan");
}
base.OnActionExecuting(actionContext);
}
}
You'll have to adjust for Apache. Hope you get the idea!
/Daniel
On Wednesday, 25 March 2015 08:42:08 UTC+1, Rokosolnik wrote:
>
> Hello.
>
> I have developed a website using angular. This website runs on apache.
>
> So from time to time more features are added to this site and I deploy new
> version.
>
> If I have website open in browser, and in the mean time a deploy a new
> version.
> When I come back to browser I can still browse...
> I should be redirected to login if new deployment...
>
> Is this possible to be detected ?
>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.