This repository was archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
56 lines (52 loc) · 1.57 KB
/
index.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
import crypto from 'crypto'
import dotenv from 'dotenv'
import main from './main'
import path from 'path'
dotenv.config()
/**
* Some configuration may be dynamically generated at startup.
* This private object allows it to be preserved during the application's runtime.
*/
const dynamicConfig: Record<string, unknown> = {}
/** String truthy values. */
const TRUE = ['1', 't', 'y', 'on', 'yes', 'true']
// Run the app
main({
api: {
prefix: process.env.API_PREFIX || '/api',
},
auth: {
jwt: {
expiresIn: parseInt(process.env.AUTH_JWT_EXPIRES_IN || '86400'),
get secret() {
if (process.env.AUTH_JWT_SECRET) return process.env.AUTH_JWT_SECRET
if (!dynamicConfig.authJwtSecret) {
const secret = crypto.randomBytes(64).toString('hex')
console.warn('AUTH_JWT_SECRET not set. Generated a JWT secret for this run only:', secret)
dynamicConfig.authJwtSecret = secret
}
return dynamicConfig.authJwtSecret as string
},
},
},
cors: undefined,
fs: {
root: path.dirname(__dirname),
},
http: {
host: process.env.HTTP_HOST || '',
port: parseInt(process.env.HTTP_PORT || '5001'),
},
log: {
level: process.env.LOG_LEVEL || 'info',
},
mongo: {
db: process.env.MONGO_DB || 'herda',
uri: process.env.MONGO_URI || 'mongodb://root:root@localhost:27017',
useTransactions: TRUE.includes(process.env.MONGO_USE_TRANSACTIONS || 'false'),
},
shutdownTimeout: parseInt(process.env.SHUTDOWN_TIMEOUT || '60000'),
}).catch(err => {
if (err) console.error(err)
process.exit(1)
})