diff --git a/src/Squidex/Startup.cs b/src/Squidex/Startup.cs index 55e56f5fe..69eea2e7a 100644 --- a/src/Squidex/Startup.cs +++ b/src/Squidex/Startup.cs @@ -68,7 +68,6 @@ namespace Squidex services.AddMemoryCache(); services.AddOptions(); services.AddRouting(); - services.AddResponseCompression(); services.AddWebpackBuilder(); services.Configure( @@ -95,8 +94,6 @@ namespace Squidex loggerFactory.AddConsole(); loggerFactory.AddDebug(); - app.UseResponseCompression(); - if (!Environment.IsDevelopment()) { app.UseMiddleware(); @@ -185,7 +182,6 @@ namespace Squidex headers.CacheControl = new CacheControlHeaderValue { MaxAge = TimeSpan.FromDays(60), - }; } }); diff --git a/src/Squidex/app-config/webpack.run.prod.js b/src/Squidex/app-config/webpack.run.prod.js index 5b9a5bb4f..cf9a21566 100644 --- a/src/Squidex/app-config/webpack.run.prod.js +++ b/src/Squidex/app-config/webpack.run.prod.js @@ -57,7 +57,7 @@ module.exports = webpackMerge.smart(runConfig, { loader: ExtractTextPlugin.extract({ fallbackLoader: 'style', loader: 'css!sass?sourceMap' }) }, { test: /\.(png|jpe?g|gif|svg|ico)(\?.*$|$)/, - loaders: ['file?hash=sha512&digest=hex&name=[hash].[ext]', 'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'] + loaders: ['file?hash=sha512&digest=hex&name=assets/[name].[hash].[ext]', 'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'] } ] }, diff --git a/src/Squidex/app/shared/guards/app-must-exist.guard.ts b/src/Squidex/app/shared/guards/app-must-exist.guard.ts index 4967c16b8..31dd1b9b7 100644 --- a/src/Squidex/app/shared/guards/app-must-exist.guard.ts +++ b/src/Squidex/app/shared/guards/app-must-exist.guard.ts @@ -8,8 +8,6 @@ import * as Ng2 from '@angular/core'; import * as Ng2Router from '@angular/router'; -import { Observable } from 'rxjs'; - import { AppsStoreService } from './../services/apps-store.service'; @Ng2.Injectable() @@ -20,17 +18,19 @@ export class AppMustExistGuard implements Ng2Router.CanActivate { ) { } - public canActivate(route: Ng2Router.ActivatedRouteSnapshot, state: Ng2Router.RouterStateSnapshot): Observable { + public canActivate(route: Ng2Router.ActivatedRouteSnapshot, state: Ng2Router.RouterStateSnapshot): Promise { const appName = route.params['appName']; const result = this.appsStore.selectApp(appName) - .take(1) - .map(app => app !== null) - .do(hasApp => { + .then(hasApp => { if (!hasApp) { this.router.navigate(['/404']); } + + return hasApp; + }).catch(() => { + this.router.navigate(['/404']); }); return result; diff --git a/src/Squidex/app/shared/services/apps-store.service.ts b/src/Squidex/app/shared/services/apps-store.service.ts index bcee3880f..899ab6d51 100644 --- a/src/Squidex/app/shared/services/apps-store.service.ts +++ b/src/Squidex/app/shared/services/apps-store.service.ts @@ -82,10 +82,10 @@ export class AppsStoreService { }); } - public selectApp(name: string | null): Observable { + public selectApp(name: string | null): Promise { this.appName$.next(name); - return this.selectedApp; + return this.selectedApp.take(1).map(app => app !== null).toPromise(); } public createApp(appToCreate: AppCreateDto): Observable { diff --git a/src/Squidex/app/shared/services/auth.service.ts b/src/Squidex/app/shared/services/auth.service.ts index e5615d0d6..570c3cdd9 100644 --- a/src/Squidex/app/shared/services/auth.service.ts +++ b/src/Squidex/app/shared/services/auth.service.ts @@ -38,6 +38,8 @@ export class Profile { export class AuthService { private readonly userManager: UserManager; private readonly isAuthenticatedChanged$ = new Subject(); + private loginCompleted = false; + private loginCache: Promise | null = null; private currentUser: Profile | null = null; private readonly isAuthenticatedChangedPublished$ = @@ -87,16 +89,18 @@ export class AuthService { } public checkLogin(): Promise { - if (this.currentUser) { - return Promise.resolve(true); + if (this.loginCompleted) { + return Promise.resolve(this.currentUser !== null); + } else if (this.loginCache) { + return this.loginCache; } else { - const promise = + this.loginCache = this.checkState(this.userManager.signinSilent()) .then(result => { return result || this.checkState(this.userManager.signinSilent()); }); - return promise; + return this.loginCache; } } @@ -143,11 +147,18 @@ export class AuthService { const resultPromise = promise .then(user => { - if (user) { - this.onAuthenticated(user); - } + this.loginCache = null; + this.loginCompleted = null; + + this.onAuthenticated(user); + return !!this.currentUser; }).catch((err) => { + this.loginCache = null; + this.loginCompleted = null; + + this.onAuthenticated(null); + return false; }); diff --git a/src/Squidex/project.json b/src/Squidex/project.json index ff3dbc065..a9c530209 100644 --- a/src/Squidex/project.json +++ b/src/Squidex/project.json @@ -15,7 +15,6 @@ "version": "1.0.0-preview2-final", "type": "build" }, - "Microsoft.AspNetCore.ResponseCompression": "1.0.0-preview1-final", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.AspNetCore.StaticFiles": "1.0.0",