diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..3659a0e --- /dev/null +++ b/default.nix @@ -0,0 +1,9 @@ +{ pkgs ? import {} }: +let +in + pkgs.mkShell { + buildInputs = [ + pkgs.nodejs_20 + ]; + +} diff --git a/package.json b/package.json index e91f11a..49c2123 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "npm run dev:frontend && npm run dev:server", "pm": "dotenv -e .env -- npx prisma migrate dev && prisma generate", "dev:frontend": "vite ./frontend", - "dev:server": "chcp 65001 && nodemon ./server/index.ts | pino-pretty", + "dev:server": "nodemon ./server/index.ts | pino-pretty", "build": "npm i && npm run build:frontend && npm run build:server", "build:frontend": "vue-tsc -p ./frontend/tsconfig.json --noEmit && vite build ./frontend --emptyOutDir", "build:server": "npx tsc -p ./server/tsconfig.json", diff --git a/server/app.ts b/server/app.ts index 50b8651..8a3baed 100644 --- a/server/app.ts +++ b/server/app.ts @@ -7,8 +7,15 @@ import health from "./routes/health.route"; import { checkauth } from "./controllers/auth.controller"; import auth from "./routes/auth.route"; import { getSavePath } from "./utils/helpers"; +import { randomBytes } from "crypto"; const startApp = async (): Promise => { + if(process.env.API_KEY === undefined || process.env.API_KEY === "") { + logger.warn("API_KEY has not been set. Generating one ourselves. WATCH OUT: this changes on every restart") + process.env.API_KEY = randomBytes(48).toString('hex') + logger.warn(`api key is '${process.env.API_KEY}'`) + } + const router = Router(); const app = express(); diff --git a/server/email.ts b/server/email.ts index 902217a..f20fcae 100644 --- a/server/email.ts +++ b/server/email.ts @@ -71,7 +71,7 @@ export const startEmail = () => { let emailPort = parseInt(process.env?.EMAIL_PORT || "25"); if (process.env.ALLOWED_FROM === undefined || process.env.ALLOWED_TO === undefined) { - logger.error("Env variables are not set correctly"); + logger.error("Env variables are not set correctly, please check 'ALLOWED_FROM' & 'ALLOWED_TO'"); process.exit(1); } diff --git a/server/frontend.ts b/server/frontend.ts index e2c4423..35c4852 100644 --- a/server/frontend.ts +++ b/server/frontend.ts @@ -1,11 +1,16 @@ import express, { static as _static, Request, Response, Router } from "express"; import { logger } from "./utils/logger"; import { resolve } from "path"; +import { randomBytes } from "crypto"; const startFrontend = (): void => { const router = Router(); const app = express(); + // Check if we have a api key otherwise we set it here + // TODO: can we always just set it here? + process.env.VITE_PUBLIC_KEY = randomBytes(48).toString('hex') + router.get("/env.js", (req: Request, res: Response) => { res.set({ "Content-Type": "text/javascript" }).send( `window.VITE_PUBLIC_KEY = "${process.env.VITE_PUBLIC_KEY}"` diff --git a/server/utils/helpers.ts b/server/utils/helpers.ts index e78267a..550f4a7 100644 --- a/server/utils/helpers.ts +++ b/server/utils/helpers.ts @@ -2,9 +2,9 @@ import { join } from "path"; import { logger } from "./logger"; export const getSavePath = (filename: string): string => { - if (process.env.UPLOAD_PATH === undefined) { - logger.error("Environmental variable upload path has not been set"); - return ""; + if (process.env.UPLOAD_PATH === undefined || process.env.UPLOAD_PATH === "") { + logger.warn("Environmental variable upload path has not been set, defaulting to /tmp"); + process.env.UPLOAD_PATH = "/tmp" } const path: string = process.env.UPLOAD_PATH;