-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
76 lines (68 loc) · 2.22 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
import express, { urlencoded, json } from 'express';
import http from 'http'
import compression from 'compression'
import color from 'colors/safe'
import reactViews from 'express-react-views'
import morgan from 'morgan'
import path from 'path'
import injectedConfigs, { EditableConfigs } from 'getSettings'
import { session } from 'controller/middlewares'
import registerAppRoute from 'controller/api'
import schedule from 'controller/schedule'
import { init as ModelInit } from 'models/model'
const app = express()
app.use(morgan('tiny'))
app.use(compression())
app.use(urlencoded())
app.use(json())
app.use(session)
const viewDir = path.join(__dirname, './frontend/views')
app.set('views', viewDir);
if (!injectedConfigs.IS_PRODUCTION_MODE) {
app.set('view engine', 'tsx')
app.engine('tsx', reactViews.createEngine({
beautify: true,
babel: {
presets: ['@babel/preset-env',
'@babel/preset-react',
['@babel/preset-typescript', {
isTSX: true,
allExtensions: true,
}],
],
plugins: [
["module-resolver", {
"root": [viewDir],
"alias": {
"@": __dirname,
}
}]
],
extensions: ['.tsx', '.ts'],
},
transformViews: true,
}))
} else {
// app.set('view engine', 'js')
// app.engine('js', reactViews.createEngine({
// beautify: true,
// // babel: { presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'] }
// // transformViews: false,
// }));
}
registerAppRoute(app)
const server = http.createServer(app)
async function start() {
await ModelInit()
server.listen(injectedConfigs.CRAWL_POOL_ADMIN_CLIENT_PORT, () => {
console.log(color.green(`the server is running on: ${injectedConfigs.CRAWL_POOL_ADMIN_CLIENT_PORT}`))
})
const isOnlyAdminClient = !!injectedConfigs.CRAWL_POOL_ADMIN_SERVER_URL
if (!isOnlyAdminClient) {
const { SERVER_RUNNING } = EditableConfigs.getConfig('proxyPoolServer')
if (SERVER_RUNNING) {
schedule.start()
}
}
}
start()