diff --git a/ormconfig.ts b/ormconfig.ts index 852ff37..bf9be07 100644 --- a/ormconfig.ts +++ b/ormconfig.ts @@ -1,4 +1,4 @@ -import { config } from 'dotenv-safe'; +import { config } from 'dotenv'; config(); export default { diff --git a/package.json b/package.json index afc485d..baae298 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "class-validator-jsonschema": "^2.0.3", "consola": "^2.15.0", "cors": "^2.8.5", + "dotenv": "^8.2.0", "express": "^4.17.1", "helmet": "^4.2.0", "jsonwebtoken": "^8.5.1", @@ -45,14 +46,13 @@ }, "devDependencies": { "@types/cors": "^2.8.8", - "@types/dotenv-safe": "^8.1.1", + "@types/dotenv": "^8.2.0", "@types/express": "^4.17.9", "@types/jsonwebtoken": "^8.5.0", "@types/multer": "^1.4.4", "@types/node": "^14.14.9", "@types/swagger-ui-express": "^4.1.2", "@types/uuid": "^8.3.0", - "dotenv-safe": "^8.2.0", "nodemon": "^2.0.6", "sqlite3": "^5.0.0", "ts-node": "^9.0.0", diff --git a/src/app.ts b/src/app.ts index fd3dc8e..664ec6f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,7 +2,7 @@ import consola from "consola"; import "reflect-metadata"; import { createExpressServer } from "routing-controllers"; import authchecker from "./authchecker"; -import { config } from './config'; +import { config, e as errors } from './config'; import loaders from "./loaders/index"; import { ErrorHandler } from './middlewares/ErrorHandler'; @@ -23,4 +23,9 @@ async function main() { ); }); } -main(); +if (errors === 0) { + main(); +} else { + console.log("error"); + // something's wrong +} diff --git a/src/config.ts b/src/config.ts index 5dd7d19..567e35b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,8 +1,22 @@ -import * as dotenvSafe from "dotenv-safe"; -dotenvSafe.config(); +import { config as configDotenv } from 'dotenv'; +configDotenv(); export const config = { - internal_port: process.env.APP_PORT || 4010, + internal_port: parseInt(process.env.APP_PORT) || 4010, development: process.env.NODE_ENV === "production", jwt_secret: process.env.JWT_SECRET || "secretjwtsecret", phone_validation_countrycode: process.env.PHONE_COUNTRYCODE || "ZZ" -} \ No newline at end of file +} +let errors = 0 +if (typeof config.internal_port !== "number") { + errors++ +} +if (typeof config.phone_validation_countrycode !== "string") { + errors++ +} +if (config.phone_validation_countrycode.length !== 2) { + errors++ +} +if (typeof config.development !== "boolean") { + errors++ +} +export let e = errors \ No newline at end of file