Skip to content

Commit a8c3af0

Browse files
committed
[DURACOM-234] Switch to standalone bootstrapping API
1 parent 0c3e9b1 commit a8c3af0

File tree

10 files changed

+189
-202
lines changed

10 files changed

+189
-202
lines changed

server.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { hasNoValue, hasValue } from './src/app/shared/empty.util';
4848

4949
import { UIServerConfig } from './src/config/ui-server-config.interface';
5050

51-
import { ServerAppModule } from './src/main.server';
51+
import bootstrap from './src/main.server';
5252

5353
import { buildAppConfig } from './src/config/config.server';
5454
import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
@@ -130,7 +130,7 @@ export function app() {
130130
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
131131
server.engine('html', (_, options, callback) =>
132132
ngExpressEngine({
133-
bootstrap: ServerAppModule,
133+
bootstrap,
134134
providers: [
135135
{
136136
provide: REQUEST,
@@ -142,10 +142,10 @@ export function app() {
142142
},
143143
{
144144
provide: APP_CONFIG,
145-
useValue: environment
146-
}
147-
]
148-
})(_, (options as any), callback)
145+
useValue: environment,
146+
},
147+
],
148+
})(_, (options as any), callback),
149149
);
150150

151151
server.engine('ejs', ejs.renderFile);
@@ -162,7 +162,7 @@ export function app() {
162162
server.get('/robots.txt', (req, res) => {
163163
res.setHeader('content-type', 'text/plain');
164164
res.render('assets/robots.txt.ejs', {
165-
'origin': req.protocol + '://' + req.headers.host
165+
'origin': req.protocol + '://' + req.headers.host,
166166
});
167167
});
168168

@@ -177,7 +177,7 @@ export function app() {
177177
router.use('/sitemap**', createProxyMiddleware({
178178
target: `${environment.rest.baseUrl}/sitemaps`,
179179
pathRewrite: path => path.replace(environment.ui.nameSpace, '/'),
180-
changeOrigin: true
180+
changeOrigin: true,
181181
}));
182182

183183
/**
@@ -186,7 +186,7 @@ export function app() {
186186
router.use('/signposting**', createProxyMiddleware({
187187
target: `${environment.rest.baseUrl}`,
188188
pathRewrite: path => path.replace(environment.ui.nameSpace, '/'),
189-
changeOrigin: true
189+
changeOrigin: true,
190190
}));
191191

192192
/**
@@ -197,7 +197,7 @@ export function app() {
197197
const RateLimit = require('express-rate-limit');
198198
const limiter = new RateLimit({
199199
windowMs: (environment.ui as UIServerConfig).rateLimiter.windowMs,
200-
max: (environment.ui as UIServerConfig).rateLimiter.max
200+
max: (environment.ui as UIServerConfig).rateLimiter.max,
201201
});
202202
server.use(limiter);
203203
}
@@ -325,7 +325,7 @@ function initCache() {
325325
botCache = new LRU( {
326326
max: environment.cache.serverSide.botCache.max,
327327
ttl: environment.cache.serverSide.botCache.timeToLive,
328-
allowStale: environment.cache.serverSide.botCache.allowStale
328+
allowStale: environment.cache.serverSide.botCache.allowStale,
329329
});
330330
}
331331

@@ -337,7 +337,7 @@ function initCache() {
337337
anonymousCache = new LRU( {
338338
max: environment.cache.serverSide.anonymousCache.max,
339339
ttl: environment.cache.serverSide.anonymousCache.timeToLive,
340-
allowStale: environment.cache.serverSide.anonymousCache.allowStale
340+
allowStale: environment.cache.serverSide.anonymousCache.allowStale,
341341
});
342342
}
343343
}
@@ -415,7 +415,7 @@ function checkCacheForRequest(cacheName: string, cache: LRU<string, any>, req, r
415415
const key = getCacheKey(req);
416416

417417
// Check if this page is in our cache
418-
let cachedCopy = cache.get(key);
418+
const cachedCopy = cache.get(key);
419419
if (cachedCopy) {
420420
if (environment.cache.serverSide.debug) { console.log(`CACHE HIT FOR ${key} in ${cacheName} cache`); }
421421

@@ -529,20 +529,20 @@ function serverStarted() {
529529
function createHttpsServer(keys) {
530530
const listener = createServer({
531531
key: keys.serviceKey,
532-
cert: keys.certificate
532+
cert: keys.certificate,
533533
}, app).listen(environment.ui.port, environment.ui.host, () => {
534534
serverStarted();
535535
});
536536

537537
// Graceful shutdown when signalled
538-
const terminator = createHttpTerminator({server: listener});
538+
const terminator = createHttpTerminator({ server: listener });
539539
process.on('SIGINT', () => {
540-
void (async ()=> {
541-
console.debug('Closing HTTPS server on signal');
542-
await terminator.terminate().catch(e => { console.error(e); });
543-
console.debug('HTTPS server closed');
544-
})();
545-
});
540+
void (async ()=> {
541+
console.debug('Closing HTTPS server on signal');
542+
await terminator.terminate().catch(e => { console.error(e); });
543+
console.debug('HTTPS server closed');
544+
})();
545+
});
546546
}
547547

548548
/**
@@ -559,14 +559,14 @@ function run() {
559559
});
560560

561561
// Graceful shutdown when signalled
562-
const terminator = createHttpTerminator({server: listener});
562+
const terminator = createHttpTerminator({ server: listener });
563563
process.on('SIGINT', () => {
564-
void (async () => {
565-
console.debug('Closing HTTP server on signal');
566-
await terminator.terminate().catch(e => { console.error(e); });
567-
console.debug('HTTP server closed.');return undefined;
568-
})();
569-
});
564+
void (async () => {
565+
console.debug('Closing HTTP server on signal');
566+
await terminator.terminate().catch(e => { console.error(e); });
567+
console.debug('HTTP server closed.');return undefined;
568+
})();
569+
});
570570
}
571571

572572
function start() {
@@ -597,7 +597,7 @@ function start() {
597597
if (serviceKey && certificate) {
598598
createHttpsServer({
599599
serviceKey: serviceKey,
600-
certificate: certificate
600+
certificate: certificate,
601601
});
602602
} else {
603603
console.warn('Disabling certificate validation and proceeding with a self-signed certificate. If this is a production server, it is recommended that you configure a valid certificate instead.');
@@ -606,7 +606,7 @@ function start() {
606606

607607
createCertificate({
608608
days: 1,
609-
selfSigned: true
609+
selfSigned: true,
610610
}, (error, keys) => {
611611
createHttpsServer(keys);
612612
});
@@ -627,7 +627,7 @@ function healthCheck(req, res) {
627627
})
628628
.catch((error) => {
629629
res.status(error.response.status).send({
630-
error: error.message
630+
error: error.message,
631631
});
632632
});
633633
}

src/app/app.component.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
NativeWindowRef,
3636
NativeWindowService,
3737
} from './core/services/window.service';
38+
import { ThemedRootComponent } from './root/themed-root.component';
3839
import { HostWindowResizeAction } from './shared/host-window.actions';
3940
import { HostWindowService } from './shared/host-window.service';
4041
import { MenuService } from './shared/menu/menu.service';
@@ -84,7 +85,6 @@ describe('App component', () => {
8485
},
8586
}),
8687
],
87-
declarations: [AppComponent], // declare the test component
8888
providers: [
8989
{ provide: NativeWindowService, useValue: new NativeWindowRef() },
9090
{ provide: MetadataService, useValue: new MetadataServiceMock() },
@@ -109,7 +109,13 @@ describe('App component', () => {
109109

110110
// waitForAsync beforeEach
111111
beforeEach(waitForAsync(() => {
112-
return TestBed.configureTestingModule(getDefaultTestBedConf());
112+
return TestBed.configureTestingModule(getDefaultTestBedConf()).overrideComponent(
113+
AppComponent, {
114+
remove: {
115+
imports: [ ThemedRootComponent ],
116+
},
117+
},
118+
);
113119
}));
114120

115121
// synchronous beforeEach

src/app/app.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AsyncPipe,
23
DOCUMENT,
34
isPlatformBrowser,
45
} from '@angular/common';
@@ -44,6 +45,7 @@ import {
4445
NativeWindowService,
4546
} from './core/services/window.service';
4647
import { distinctNext } from './core/shared/distinct-next';
48+
import { ThemedRootComponent } from './root/themed-root.component';
4749
import { HostWindowResizeAction } from './shared/host-window.actions';
4850
import { IdleModalComponent } from './shared/idle-modal/idle-modal.component';
4951
import { CSSVariableService } from './shared/sass-helper/css-variable.service';
@@ -55,6 +57,11 @@ import { ThemeService } from './shared/theme-support/theme.service';
5557
templateUrl: './app.component.html',
5658
styleUrls: ['./app.component.scss'],
5759
changeDetection: ChangeDetectionStrategy.OnPush,
60+
standalone: true,
61+
imports: [
62+
ThemedRootComponent,
63+
AsyncPipe,
64+
],
5865
})
5966
export class AppComponent implements OnInit, AfterViewInit {
6067
notificationOptions;

0 commit comments

Comments
 (0)