This repository has been archived by the owner on Jan 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.ts
123 lines (105 loc) · 5.27 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { enableProdMode } from '@angular/core';
// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import * as express from 'express';
import { join } from 'path';
import * as xFrameOptions from 'x-frame-options';
import * as healthcheck from "@hmcts/nodejs-healthcheck";
import * as noCache from 'nocache';
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
// Express server
const app = express();
const appHealth = express();
const PORT = process.env.PORT || 3451;
const DIST_FOLDER = join(process.cwd());
const CONFIG = {
'login_url': process.env['IDAM_LOGIN_URL'] || 'https://localhost:3501/login',
'logout_url': process.env['CCD_GW_LOGOUT_URL'] || 'http://localhost:3453/logout',
'api_url': process.env['CCD_API_URL'] || 'http://localhost:3453/aggregated',
'case_data_url': process.env['CCD_DATA_URL'] || 'http://localhost:3453/data',
'document_management_url': process.env['DM_URL'] || 'http://localhost:3453/documents',
'remote_document_management_url': process.env['DM_URL_REMOTE'] || 'https://api-gateway.dev.dm.reform.hmcts.net/documents',
'annotation_api_url':process.env['ANNOTATION_API_URL'] || 'http://localhost:3453/em-anno',
'pagination_page_size': parseInt(process.env['CCD_PAGE_SIZE'], 10) || 25,
'postcode_lookup_url': process.env['POSTCODE_LOOKUP_URL'] || 'http://localhost:3453/addresses?postcode=${postcode}',
'oauth2_token_endpoint_url': process.env['CCD_GW_OAUTH2_URL'] || 'http://localhost:3453/oauth2',
'oauth2_client_id': process.env['CCD_GW_OAUTH2_CLIENT_ID'] || 'ccd_gateway',
'print_service_url': process.env['PRINT_SERVICE_URL'] || 'http://localhost:3453/print',
'remote_print_service_url': process.env['PRINT_SERVICE_URL_REMOTE'] || 'https://return-case-doc.dev.ccd.reform.hmcts.net',
'smart_survey_url': process.env['SMART_SURVEY_URL'] || 'https://www.smartsurvey.co.uk/s/CCDfeedback/',
'unsupported_browser_url': process.env['UNSUPPORTED_BROWSER_URL'] || 'https://www.gov.uk/help/browsers',
'activity_url': process.env['CCD_ACTIVITY_URL'] || '',
'payments_url': process.env['PAYMENTS_URL'] || 'http://localhost:3453/payments',
'pay_bulk_scan_url': process.env['PAY_BULKSCAN_URL'] || 'http://localhost:3453/pay-bulkscan',
'chrome_min_required_version': parseInt(process.env['CHROME_MIN_REQUIRED_VERSION'], 10) || 67,
'ie_min_required_version': parseInt(process.env['IE_MIN_REQUIRED_VERSION'], 10) || 11,
'edge_min_required_version': parseInt(process.env['EDGE_MIN_REQUIRED_VERSION'], 10) || 17,
'firefox_min_required_version': parseInt(process.env['FIREFOX_MIN_REQUIRED_VERSION'], 10) || 60,
'activity_next_poll_request_ms': parseInt(process.env['CCD_ACTIVITY_NEXT_POLL_REQUEST_MS'], 10) || 5000,
'activity_retry': parseInt(process.env['CCD_ACTIVITY_RETRY'], 10) || 5,
'activity_batch_collection_delay_ms': parseInt(process.env['CCD_ACTIVITY_BATCH_COLLECTION_DELAY_MS'], 10) || 1,
'activity_max_request_per_batch': parseInt(process.env['CCD_ACTIVITY_MAX_REQUEST_PER_BATCH'], 10) || 25,
'appInsights_enabled': process.env['APPINSIGHTS_ENABLED'] || 'false',
'appInsights_roleName': process.env['APPINSIGHTS_ROLE'] || 'ccd-case-management-web',
'shutter_redirect_url': process.env['SHUTTER_REDIRECT_URL'] || '',
'shutter_redirect_wait': parseInt(process.env['SHUTTER_REDIRECT_WAIT'], 10) || 10
};
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');
import { AppConfig } from './src/app/app.config';
import { AppServerConfig } from './src/app/app.server.config';
import * as config from 'config';
import * as propertiesVolume from '@hmcts/properties-volume';
propertiesVolume.addTo(config);
const enableAppInsights = require('./src/app/app-insights/app-insights');
let appServerConfig = new AppServerConfig(CONFIG);
enableAppInsights(appServerConfig);
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP),
{ provide: AppConfig, useValue: appServerConfig },
]
}));
const poweredByHeader = 'x-powered-by';
app.disable(poweredByHeader);
appHealth.disable(poweredByHeader);
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
app.use(xFrameOptions());
// health check
const healthConfig = {
checks: {},
};
healthcheck.addTo(appHealth, healthConfig);
app.use(appHealth);
app.get('/config', (req, res) => {
res.status(200).json(CONFIG);
});
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser'), {
maxAge: '1y'
}));
// No cache for any routes handled by Universal
app.use(noCache());
// Enable caching for media-viewer
app.use('/media-viewer', function (req, res, next) {
res.set('Cache-Control', 'public, max-age=31536000')
res.removeHeader('Expires')
res.removeHeader('Pragma')
res.removeHeader('Surrogate-Control')
next()
});
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render('index', { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});