-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(envs): add validations using
envalid
- Loading branch information
phucvinh57
committed
Jun 7, 2023
1 parent
36afce9
commit 4cfff3e
Showing
8 changed files
with
41 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
import { config as configEnv } from 'dotenv'; | ||
import { str, cleanEnv } from 'envalid'; | ||
|
||
export const ENVIRONMENT = !process.env.NODE_ENV ? 'development' : (process.env.NODE_ENV as Environment); | ||
export const JWT_SECRET = process.env.JWT_SECRET as string; | ||
export const COOKIE_SECRET = process.env.COOKIE_SECRET as string; | ||
export const CORS_WHITE_LIST = process.env.CORS_WHITE_LIST === undefined ? [] : process.env.CORS_WHITE_LIST.split(','); | ||
configEnv(); | ||
|
||
export const envs = cleanEnv(process.env, { | ||
NODE_ENV: str<Environment>({ | ||
devDefault: 'development', | ||
choices: ['development', 'test', 'production', 'staging'] | ||
}), | ||
JWT_SECRET: str(), | ||
COOKIE_SECRET: str(), | ||
CORS_WHITE_LIST: str() | ||
}); | ||
|
||
export const CORS_WHITE_LIST = envs.CORS_WHITE_LIST.split(','); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { ENVIRONMENT } from '@configs'; | ||
import { envs } from '@configs'; | ||
|
||
export const cookieOptions = { | ||
signed: false, | ||
secure: ENVIRONMENT === 'production', | ||
secure: envs.isProduction, | ||
path: '/', | ||
httpOnly: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters