This repository has been archived by the owner on Jun 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplication.ts
123 lines (98 loc) · 3.16 KB
/
application.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 { judgeLookUp } from './api/lib/util'
const healthcheck = require('@hmcts/nodejs-healthcheck');
/*const { InfoContributor, infoRequestHandler } = require('@hmcts/info-provider');*/
import * as express from 'express';
import { config } from './config';
import { appInsights } from './api/lib/appInsights';
import { securityHeaders } from './api/lib/middleware/securityHeaders';
import * as log4jui from './api/lib/log4jui';
import * as globalTunnel from 'global-tunnel-ng';
const apiRoute = require('./api');
config.environment = process.env.JUI_ENV || 'local';
const app = express();
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const redis = require('redis');
const redisStore = require('connect-redis')(session);
const tlsOptions = {
password: process.env.REDIS_PASSWORD,
tls: true
};
const redisClient = redis.createClient(
process.env.REDIS_PORT,
process.env.REDIS_HOST,
tlsOptions,
);
redisClient.on('error', err => {
console.log('Redis client error: ', err);
});
app.use(securityHeaders);
app.set('trust proxy', 1);
app.use(
session({
cookie: {
httpOnly: true,
maxAge: 1800000,
secure: config.secureCookie !== false
},
name: 'jui-webapp',
resave: true,
saveUninitialized: true,
secret: config.sessionSecret,
store: new redisStore({
client: redisClient,
ttl: 86400
})
})
);
app.use(appInsights);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use((req, res, next) => {
// Set cookie for angular to know which config to use
const platform = process.env.JUI_ENV || 'local';
res.cookie('platform', platform);
next();
});
if (config.proxy) {
globalTunnel.initialize({
host: config.proxy.host,
port: config.proxy.port
});
}
function healthcheckConfig(msUrl) {
return healthcheck.web(`${msUrl}/health`, {
timeout: 6000,
deadline: 6000
});
}
let healthchecks = {
checks: {
ccd_data_api: healthcheckConfig(config.services.ccd_data_api),
ccd_def_api: healthcheckConfig(config.services.ccd_def_api),
idam_api: healthcheckConfig(config.services.idam_api),
s2s: healthcheckConfig(config.services.s2s),
draft_store_api: healthcheckConfig(config.services.draft_store_api),
dm_store_api: healthcheckConfig(config.services.dm_store_api),
em_anno_api: healthcheckConfig(config.services.em_anno_api),
em_npa_api: healthcheckConfig(config.services.em_npa_api),
coh_cor_api: healthcheckConfig(config.services.coh_cor_api)
}
};
healthcheck.addTo(app, healthchecks);
app.get('/oauth2/callback', apiRoute);
app.get('/logout', apiRoute);
app.use('/api', apiRoute);
const logger = log4jui.getLogger('Application');
try {
judgeLookUp('a@a.com', true);
} catch (e) {
logger.error('exiting due to malformed crypt file');
// process.exit(1);
}
logger.info(
`Started up on ${config.environment || 'local'} using ${config.protocol}`
);
module.exports = app;