-
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.
- Loading branch information
0 parents
commit 1f1a455
Showing
28 changed files
with
8,060 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DATABASE=mongodb+srv://bilel_salem:Ycm2DYC8YjiZeezS@cluster0.udmqyu3.mongodb.net/restApiTutorial?retryWrites=true&w=majority | ||
JWT_SECRET=AZERTYUIOP1234567890-bilel-salem | ||
JWT_EXPIRES_IN=90d | ||
JWT_COOKIE_EXPIRES_IN=90 | ||
PORT=3000 | ||
NODE_ENV=development |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import path from "path"; | ||
import dotenv from "dotenv"; | ||
dotenv.config({ path: path.resolve(__dirname, "../config.env") }); | ||
interface ENV { | ||
NODE_ENV: string | undefined; | ||
DATABASE: string | undefined; | ||
PORT: number | undefined; | ||
|
||
JWT_SECRET: string | undefined; | ||
JWT_EXPIRES_IN: string | undefined; | ||
JWT_COOKIE_EXPIRES_IN: string | undefined; | ||
} | ||
interface Config { | ||
NODE_ENV: string; | ||
DATABASE: string; | ||
PORT: number; | ||
|
||
JWT_SECRET: string; | ||
JWT_EXPIRES_IN: string; | ||
JWT_COOKIE_EXPIRES_IN: string; | ||
} | ||
const getConfig = (): ENV => { | ||
return { | ||
NODE_ENV: process.env.NODE_ENV, | ||
DATABASE: process.env.DATABASE, | ||
|
||
JWT_SECRET: process.env.JWT_SECRET, | ||
JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN, | ||
PORT: process.env.PORT ? Number(process.env.PORT) : undefined, | ||
JWT_COOKIE_EXPIRES_IN: process.env.JWT_COOKIE_EXPIRES_IN, | ||
}; | ||
}; | ||
const getSanitzedConfig = (config: ENV): Config => { | ||
for (const [key, value] of Object.entries(config)) { | ||
if (value === undefined) { | ||
throw new Error(`Missing key ${key} in config.env`); | ||
} | ||
} | ||
return config as Config; | ||
}; | ||
const config = getConfig(); | ||
const sanitizedConfig = getSanitzedConfig(config); | ||
export default sanitizedConfig; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["."], | ||
"ext": ".ts,.js,.yaml", | ||
"ignore": [], | ||
"exec": "ts-node-dev --respawn --transpile-only ./src/server.ts" | ||
} |
Oops, something went wrong.