Fixes ssr

parent 55ccd739
Pipeline #18375 passed with stages
in 10 minutes and 4 seconds
......@@ -48,9 +48,6 @@ build:
- echo $STAGING_SERVER_ENDPOINTS > src/assets/serverEndpoint.json
- npm install
- npm run build:SSR
- cd dist
- node server &
- sleep 15s
artifacts:
paths:
- dist
......
......@@ -18,6 +18,19 @@ import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { DefaultSettings } from './src/lib/default.settings';
Error.stackTraceLimit = Infinity;
console.error = (msg) => {
try {
throw Error(msg);
} catch (ex) {
console.log('-------------------------');
console.log(ex.name + ' - ' + ex.message);
console.log(ex.stack);
console.log('-------------------------');
}
};
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
......
<nav class="navbar navbar-header flex-nowrap"
id="header">
<div class="arsnova-logo d-flex align-items-center pointer">
<!--suppress HtmlUnknownAttribute -->
<svg [routerLink]="['/']" version="1.1" id="arsnova-logo-image" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 1024 1024" xml:space="preserve">
<!--suppress HtmlUnknownAttribute -->
<a [routerLink]="['/']">
<svg version="1.1" id="arsnova-logo-image" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 1024 1024" xml:space="preserve">
<g id="text">
<text transform="translate(512 200)" class="arsnova-logo-origin" [innerHTML]="origin"></text>
<text transform="translate(512 200)" class="arsnova-logo-origin">{{origin}}</text>
<text transform="matrix(1 0 0 1 69 500)" class="arsnova-logo-ars">ars</text>
<text transform="matrix(1 0 0 1 420 500)" class="arsnova-logo-nova">nova</text>
<text transform="matrix(1 0 0 1 512 820)" class="arsnova-logo-click">.click</text>
</g>
</svg>
</a>
</div>
<div class="header-title d-flex align-items-center">
<div class="center-block">
......
......@@ -158,43 +158,29 @@ export class HomeComponent implements OnInit, OnDestroy {
}
public ngOnInit(): void {
if (isPlatformServer(this.platformId)) {
console.log('homecomponent ngoninit - isserver');
return;
}
console.log('homecomponent ngoninit - isclient');
this._routerSubscription = this.route.params.subscribe(async params => {
if (!Object.keys(params).length || !params.themeId || !params.languageId) {
const theme = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME).toPromise();
const theme = this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME).toPromise();
if (theme) {
return;
}
await this.storageService.create(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME, DefaultSettings.defaultQuizSettings.theme).toPromise();
if (isPlatformServer(this.platformId)) {
const interval = setInterval(() => {
if (isPlatformBrowser(this.platformId)) {
clearInterval(interval);
this.themesService.updateCurrentlyUsedTheme();
}
}, 5000);
} else {
this.themesService.updateCurrentlyUsedTheme();
}
this.themesService.updateCurrentlyUsedTheme();
return;
}
if (isPlatformBrowser(this.platformId)) {
await this.storageService.create(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME, params.themeId).toPromise();
this.themesService.updateCurrentlyUsedTheme();
} else {
const interval = setInterval(() => {
if (isPlatformBrowser(this.platformId)) {
clearInterval(interval);
this.themesService.updateCurrentlyUsedTheme();
}
}, 5000);
}
await this.storageService.create(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME, params.themeId).toPromise();
this.i18nService.setLanguage(<LANGUAGE>params.languageId.toUpperCase());
this.themesService.updateCurrentlyUsedTheme();
});
}
......
......@@ -58,7 +58,6 @@ export class RootComponent implements OnInit, AfterViewInit {
private storageService: StorageService,
private userService: UserService,
) {
this.themesService.updateCurrentlyUsedTheme();
}
public getFooterBarElements(): EventEmitter<Array<IFooterBarElement>> {
......@@ -139,7 +138,8 @@ export class RootComponent implements OnInit, AfterViewInit {
};
this.storageService.create(DB_TABLE.CONFIG, STORAGE_KEY.INTRO_STATE, introState).subscribe();
}
if (hasStartedIntroJs || !await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.SHOW_PRODUCT_TOUR).toPromise() || introState[route].completed) {
if (hasStartedIntroJs || !await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.SHOW_PRODUCT_TOUR).toPromise()
|| introState[route].completed) {
return;
}
const customIntroJs = introJs();
......
import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { IMessage, IMessageStep } from 'arsnova-click-v2-types/dist/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/dist/communication_protocol';
......@@ -83,6 +84,7 @@ export class ConnectionService {
public sendMessage(message: IMessage): void {
if (!this._websocketAvailable) {
console.log('connectionservice - websocket not available, waiting 500ms');
setTimeout(() => {
this.sendMessage(message);
}, 500);
......@@ -110,6 +112,10 @@ export class ConnectionService {
}
public initConnection(overrideCurrentState?: boolean): Promise<any> {
if (isPlatformServer(this.platformId)) {
return new Promise<any>(resolve => resolve());
}
return new Promise(async (resolve) => {
if ((
this.pending || this.serverAvailable
......@@ -124,6 +130,7 @@ export class ConnectionService {
this.serverAvailable = true;
this._websocketAvailable = true;
setTimeout(() => {
console.log('connectionservice - websocket not available, waiting 500ms');
this.calculateRTT(new Date().getTime());
}, 500);
resolve2(httpData);
......@@ -187,6 +194,7 @@ export class ConnectionService {
if (!this._websocketAvailable) {
setTimeout(() => {
console.log('connectionservice - websocket not available, waiting 500ms');
this.sendAuthorizationMessage(hashtag, step, auth);
}, 500);
return;
......
......@@ -75,6 +75,7 @@ export class ThemesService {
}),
]);
const usedTheme = themeConfig[0] || themeConfig[1] || themeConfig[2];
console.log('themes-service ', usedTheme);
const themeDataset = document.getElementsByTagName('html').item(0).dataset['theme'];
if (!document.getElementById('link-manifest') && themeDataset === usedTheme) {
......
......@@ -36,6 +36,7 @@ export class WebsocketService {
if (socket.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify(data));
} else if (socket.readyState === WebSocket.CONNECTING) {
console.log('websocketservice - waiting 500ms for connection');
setTimeout(() => (observer.next(data)), 500);
}
},
......
......@@ -12,20 +12,24 @@ interface INamedType extends Type<Function> {
@Injectable()
export class ArsnovaClickAngulartics2Piwik extends Angulartics2Piwik {
constructor(
private _angulartics2: Angulartics2,
private route: ActivatedRoute,
) {
constructor(private _angulartics2: Angulartics2, private route: ActivatedRoute) {
super(_angulartics2);
}
public pageTrack(path: string, location?: any): void {
try {
_paq.push(['setDocumentTitle', (<INamedType>this.getFirstRoutingChild(this.route).component).TYPE]);
_paq.push([
'setDocumentTitle',
(
<INamedType>this.getFirstRoutingChild(this.route).component
).TYPE,
]);
_paq.push(['setCustomUrl', path]);
_paq.push(['trackPageView']);
} catch (e) {
if (!(e instanceof ReferenceError)) {
if (!(
e instanceof ReferenceError
)) {
throw e;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment