diff --git a/server/src/app.ts b/server/src/app.ts index 519b19a..a73d344 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -11,44 +11,56 @@ import {LOG} from "./logging/logger"; import {apiRequestLogger} from "./logging/api-request-logger"; import * as ENV from "./config/envConfig"; - const app: Express = express(); const port: string = ENV.SERVER_PORT; const path: string = __dirname + "/views/"; -//get environemnt mode for local dev and set cors options -LOG.info("env mode: " + ENV.NODE_ENV); -if(ENV.NODE_ENV === "dev"){ - app.use(cors(getCorstOptions())) - // app.use(cors()) +const mainIndexPath: string = path + "index.html"; + +// Get environment mode for local dev and set CORS options +if (ENV.NODE_ENV === "dev") { + app.use(cors(getCorstOptions())); } -app.use(express.static(path)); -app.use(bodyParser.json()); +// Middleware app.use(apiRequestLogger); -app.use(authorizationRoutes); -app.use(routes); +// Static files config with dynamic base path +const basePath = ENV.BASE_PATH || "/"; +app.use(basePath, express.static(path)); +app.use(bodyParser.json()); +// API routes +app.use(basePath, authorizationRoutes); +app.use(basePath, routes); -app.get("/", (req: Request, res: Response) => { - res.sendFile(path + "index.html"); +// Static files route with dynamic base path +app.get(basePath + "/", (req: Request, res: Response) => { + console.log("Serving main index at:", mainIndexPath); + res.sendFile(mainIndexPath); }); -app.get("*", (req: Request, res: Response) => { - res.sendFile(path + "index.html"); +// Catch-all route to handle all other requests +app.get(basePath + "/*", (req: Request, res: Response) => { + console.log("Catch-all route, serving main index at:", mainIndexPath); + res.sendFile(mainIndexPath); }); -app.listen(port, () => { - LOG.info(`⚡️[server]: Server is running at 0.0.0.0 ${port}`); +// Server startup +app.listen(port, async () => { + LOG.info(`⚡️[server]: Server is running at : ${port}`); + LOG.info("env mode: " + ENV.NODE_ENV); + LOG.info("is seb-server integrated: " + ENV.SEB_SERVER_INTEGRATED_MODE); + LOG.info("base path: " + ENV.BASE_PATH); + LOG.info(`screen-proctoring-server: ${ENV.PROCTOR_SERVER_URL}${ENV.PROCTOR_SERVER_PORT}`); }); -function getCorstOptions(): object{ +function getCorstOptions(): object { return { origin: `${ENV.DEV_SERVER_URL}:${ENV.DEV_SERVER_PORT}`, allowedHeaders: "Content-Type, authorization", methods: "GET, POST", credentials: true, }; -} \ No newline at end of file +} diff --git a/server/src/config/envConfig.ts b/server/src/config/envConfig.ts index 67097c4..84315fa 100644 --- a/server/src/config/envConfig.ts +++ b/server/src/config/envConfig.ts @@ -13,9 +13,18 @@ export const PROCTOR_SERVER_PASSWORD = process.env.PROCTOR_SERVER_PASSWORD; export const SEB_SERVER_INTEGRATED_MODE = process.env.SEB_SERVER_INTEGRATED_MODE; +export const BASE_PATH = getBasePath(); + function getServerPort(){ if(!process.env.PROCTOR_SERVER_PORT){ return ""; } return ":" + process.env.PROCTOR_SERVER_PORT; +}; + +function getBasePath(){ + if(!process.env.VITE_BASE_PATH){ + return ""; + } + return process.env.VITE_BASE_PATH; }; \ No newline at end of file