-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
85 lines (64 loc) · 1.98 KB
/
app.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
import http from 'node:http'
import path from 'node:path'
import cookieParser from 'cookie-parser'
import Debug from 'debug'
import { asyncExitHook } from 'exit-hook'
import express from 'express'
import schedule from 'node-schedule'
import { getConfigProperty } from './helpers/functions.config.js'
import initializeAutocompleteModule from './modules/autocomplete/initializeAutocompleteModule.js'
import initializePurchaseOrderApprovalsModule from './modules/purchaseOrderApprovals/initializePurchaseOrderApprovalsModule.js'
import initializeTempFolderCleanupModule from './modules/tempFolderCleanup/initializeTempFolderCleanupModule.js'
import initializeWorktechUpdateModule from './modules/worktechUpdate/initializeWorktechUpdateModule.js'
const debug = Debug('faster-web-helper:app')
/*
* Initialize app
*/
const app = express()
app.set('views', path.join('views'))
app.set('view engine', 'ejs')
app.use((request, _response, next) => {
debug(`${request.method} ${request.url}`)
next()
})
app.use(express.json())
app.use(
express.urlencoded({
extended: false
})
)
app.use(cookieParser())
/*
* Initialize modules
*/
if (getConfigProperty('modules.autocomplete.isEnabled')) {
await initializeAutocompleteModule(app)
}
if (getConfigProperty('modules.inventoryScanner.isEnabled')) {
debug('Initializing Inventory Scanner')
}
if (getConfigProperty('modules.worktechUpdate.isEnabled')) {
await initializeWorktechUpdateModule()
}
if (getConfigProperty('modules.tempFolderCleanup.isEnabled')) {
await initializeTempFolderCleanupModule()
}
if (getConfigProperty('modules.purchaseOrderApprovals.isEnabled')) {
initializePurchaseOrderApprovalsModule(app)
}
/*
* Initialize server
*/
const httpPort = getConfigProperty('webServer.httpPort')
const httpServer = http.createServer(app)
httpServer.listen(httpPort)
debug(`HTTP listening on ${httpPort.toString()}`)
asyncExitHook(
async () => {
await schedule.gracefulShutdown()
httpServer.close()
},
{
wait: 1000
}
)