-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
121 lines (107 loc) · 3.02 KB
/
settings.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
import { DocumentBuilder } from '@nestjs/swagger'
import { Prisma } from '@prisma/client'
import dotenv from 'dotenv'
import { dotEnvOptions } from './dotenv-options'
dotenv.config(dotEnvOptions)
console.log(`NODE_ENV environment: ${process.env.NODE_ENV}`)
const getCorsConfig = () => {
const { NODE_ENV } = process.env
if (NODE_ENV === 'prod') {
return {
origin: ['https://otl.kaist.ac.kr', 'http://otl.kaist.ac.kr', 'https://otl.sparcs.org', 'http://otl.sparcs.org'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
}
}
if (NODE_ENV === 'dev') {
return {
origin: ['https://otl.dev.sparcs.org', 'http://localhost:5173'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
}
}
return {
origin: ['http://localhost:5173', 'http://localhost:8000'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
}
}
const getPrismaConfig = (): Prisma.PrismaClientOptions => ({
datasources: {
db: {
url: process.env.DATABASE_URL,
},
},
errorFormat: 'pretty',
log: [
// {
// emit: 'event',
// level: 'query',
// },
{
emit: 'stdout',
level: 'error',
},
{
emit: 'stdout',
level: 'info',
},
// {
// emit: 'stdout',
// level: 'warn',
// },
],
})
const getRedisConfig = () => ({
url: process.env.REDIS_URL,
})
const getReplicatedPrismaConfig = (): Prisma.PrismaClientOptions => ({})
const getAWSConfig = () => ({})
const getJwtConfig = () => ({
secret: process.env.JWT_SECRET,
signOptions: {
expiresIn: process.env.EXPIRES_IN,
refreshExpiresIn: process.env.REFRESH_EXPIRES_IN,
},
})
const getSsoConfig = (): any => ({
ssoIsBeta: process.env.SSO_IS_BETA !== 'false',
ssoClientId: process.env.SSO_CLIENT_ID,
ssoSecretKey: process.env.SSO_SECRET_KEY,
})
const getSyncConfig = () => ({
apiKey: process.env.SYNC_SECRET,
slackKey: process.env.SLACK_KEY,
})
const getVersion = () => String(process.env.npm_package_version)
const getSwaggerConfig = () => {
const config = new DocumentBuilder()
.setTitle('OTLPlus-server')
.setDescription('The OTL-server API description')
.setVersion('1.0')
.build()
return config
}
const staticConfig = (): any => ({
file_path:
process.env.DOCKER_DEPLOY === 'true' ? '/var/www/otlplus-server/apps/server/static/' : 'apps/server/static/',
})
export default () => ({
ormconfig: () => getPrismaConfig(),
ormReplicatedConfig: () => getReplicatedPrismaConfig(),
awsconfig: () => getAWSConfig(),
getRedisConfig: () => getRedisConfig(),
getJwtConfig: () => getJwtConfig(),
getSsoConfig: () => getSsoConfig(),
getCorsConfig: () => getCorsConfig(),
syncConfig: () => getSyncConfig(),
getVersion: () => getVersion(),
getStaticConfig: () => staticConfig(),
getSwaggerConfig: () => getSwaggerConfig(),
})