generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
executable file
·25 lines (22 loc) · 924 Bytes
/
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
// Require app insights before anything else to allow for instrumentation of bunyan and express
import 'applicationinsights'
import * as https from 'https'
import fs from 'fs'
import { app, metricsApp } from './server/index'
import logger from './logger'
import config from './server/config'
if (config.certificate.key && config.certificate.cert) {
const key = fs.readFileSync(config.certificate.key, 'utf8')
const cert = fs.readFileSync(config.certificate.cert, 'utf8')
const httpsServer = https.createServer({ key, cert }, app)
httpsServer.listen(app.get('port'), () => {
logger.info(`Server listening on https://localhost:${app.get('port')}`)
})
} else {
app.listen(app.get('port'), () => {
logger.info(`Server listening on http://localhost:${app.get('port')}`)
})
}
metricsApp.listen(metricsApp.get('port'), () => {
logger.info(`Metrics server listening on port ${metricsApp.get('port')}`)
})