-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
84 lines (75 loc) · 2.7 KB
/
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
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
import { bool, envsafe, invalidEnvError, makeValidator, str } from 'envsafe'
import { browserEnv } from './browser'
if (process.browser) {
throw new Error(
'This should only be included on the client (but the env vars wont be exposed)'
)
}
const googleParser = makeValidator<string>((input) => {
if (process.env.AUTH_PROVIDER === 'google' && input === '') {
throw invalidEnvError('google config', input)
}
return input
})
const githubParser = makeValidator<string>((input) => {
if (process.env.AUTH_PROVIDER === 'github' && input === '') {
throw invalidEnvError('github config', input)
}
return input
})
const oktaParser = makeValidator<string>((input) => {
if (process.env.AUTH_PROVIDER === 'okta' && input === '') {
throw invalidEnvError('okta config', input)
}
return input
})
const cloudinaryParser = makeValidator<string>((input) => {
if (browserEnv.NEXT_PUBLIC_ENABLE_IMAGE_UPLOAD && input === '') {
throw invalidEnvError('cloudinary config', input)
}
return input
})
const slackParser = makeValidator<string>((input) => {
if (process.env.ENABLE_SLACK_POSTING && input === '') {
throw invalidEnvError('slack config', input)
}
return input
})
const rollbarParser = makeValidator<string>((input) => {
if (process.env.ROLLBAR_SERVER_TOKEN && input === '') {
throw invalidEnvError('rollbar server config', input)
}
return input
})
export const serverEnv = {
...browserEnv,
...envsafe({
DATABASE_URL: str(),
NEXT_APP_URL: slackParser({
allowEmpty: true,
devDefault: 'http://localhost:3000',
}),
NEXTAUTH_SECRET: str({
devDefault: 'foobar',
}),
DEBUG: bool({ default: false }),
MOCK_LOGIN: bool({ default: false }),
GOOGLE_CLIENT_ID: googleParser({ allowEmpty: true, default: '' }),
GOOGLE_CLIENT_SECRET: googleParser({ allowEmpty: true, default: '' }),
GITHUB_ID: githubParser({ allowEmpty: true, default: '' }),
GITHUB_SECRET: githubParser({ allowEmpty: true, default: '' }),
GITHUB_ALLOWED_ORG: githubParser({ allowEmpty: true, default: '' }),
OKTA_CLIENT_ID: oktaParser({ allowEmpty: true, default: '' }),
OKTA_CLIENT_SECRET: oktaParser({ allowEmpty: true, default: '' }),
OKTA_ISSUER: oktaParser({ allowEmpty: true, default: '' }),
CLOUDINARY_CLOUD_NAME: cloudinaryParser({ allowEmpty: true, default: '' }),
CLOUDINARY_API_KEY: cloudinaryParser({ allowEmpty: true, default: '' }),
CLOUDINARY_API_SECRET: cloudinaryParser({ allowEmpty: true, default: '' }),
ENABLE_SLACK_POSTING: bool({ default: false }),
SLACK_WEBHOOK_URL: slackParser({ allowEmpty: true, default: '' }),
ROLLBAR_SERVER_TOKEN: rollbarParser({
allowEmpty: false,
devDefault: 'foobar',
}),
}),
}