diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4b56232 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# NodeJs +node_modules/ +dist/ +.git/ +export/ +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..250b814 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:18-alpine AS build + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . /app + +RUN npm run build + +FROM node:18-alpine AS prod + +WORKDIR /app + +COPY --from=build /app/dist /app/dist +COPY --from=build /app/node_modules /app/node_modules +COPY --from=build /app/package.json /app/package.json +COPY --from=build /app/.env /app/.env + +EXPOSE 5000 + +CMD [ "npm", "run", "start" ] \ No newline at end of file diff --git a/src/env.defaults.ts b/src/env.defaults.ts index 459baa6..2ad0925 100644 --- a/src/env.defaults.ts +++ b/src/env.defaults.ts @@ -23,20 +23,20 @@ export const CLUB_NAME = process.env.CLUB_NAME ?? ""; export function configCheck() { if (DB_TYPE != "mysql" && DB_TYPE != "sqlite") throw new Error("set valid value to DB_TYPE (mysql|sqlite)"); - if (DB_HOST == "" ?? typeof DB_HOST != "string") throw new Error("set valid value to DB_HOST"); - if (DB_NAME == "" ?? typeof DB_NAME != "string") throw new Error("set valid value to DB_NAME"); - if (DB_USERNAME == "" ?? typeof DB_USERNAME != "string") throw new Error("set valid value to DB_USERNAME"); - if (DB_PASSWORD == "" ?? typeof DB_PASSWORD != "string") throw new Error("set valid value to DB_PASSWORD"); + if (DB_HOST == "" || typeof DB_HOST != "string") throw new Error("set valid value to DB_HOST"); + if (DB_NAME == "" || typeof DB_NAME != "string") throw new Error("set valid value to DB_NAME"); + if (DB_USERNAME == "" || typeof DB_USERNAME != "string") throw new Error("set valid value to DB_USERNAME"); + if (DB_PASSWORD == "" || typeof DB_PASSWORD != "string") throw new Error("set valid value to DB_PASSWORD"); if (typeof SERVER_PORT != "number") throw new Error("set valid numeric value to SERVER_PORT"); - if (JWT_SECRET == "" ?? typeof JWT_SECRET != "string") throw new Error("set valid value to JWT_SECRET"); + if (JWT_SECRET == "" || typeof JWT_SECRET != "string") throw new Error("set valid value to JWT_SECRET"); checkMS(JWT_EXPIRATION, "JWT_EXPIRATION"); checkMS(REFRESH_EXPIRATION, "REFRESH_EXPIRATION"); - if (MAIL_USERNAME == "" ?? typeof MAIL_USERNAME != "string") throw new Error("set valid value to MAIL_USERNAME"); - if (MAIL_PASSWORD == "" ?? typeof MAIL_PASSWORD != "string") throw new Error("set valid value to MAIL_PASSWORD"); - if (MAIL_HOST == "" ?? typeof MAIL_HOST != "string") throw new Error("set valid value to MAIL_HOST"); + if (MAIL_USERNAME == "" || typeof MAIL_USERNAME != "string") throw new Error("set valid value to MAIL_USERNAME"); + if (MAIL_PASSWORD == "" || typeof MAIL_PASSWORD != "string") throw new Error("set valid value to MAIL_PASSWORD"); + if (MAIL_HOST == "" || typeof MAIL_HOST != "string") throw new Error("set valid value to MAIL_HOST"); if (typeof MAIL_PORT != "number") throw new Error("set valid numeric value to MAIL_PORT"); if (MAIL_SECURE != "true" && MAIL_SECURE != "false") throw new Error("set 'true' or 'false' to MAIL_SECURE"); } diff --git a/src/index.ts b/src/index.ts index 6fd0f99..38374a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ const app = express(); import router from "./routes/index"; import { PermissionObject } from "./type/permissionTypes"; router(app); -app.listen(SERVER_PORT, () => { +app.listen(process.env.NODE_ENV ? SERVER_PORT : 5000, () => { console.log(`listening on *:${SERVER_PORT}`); });