import cors from "cors"; import express, { type NextFunction, type Request, type Response, } from "express"; import { RegisterRoutes } from "./generated/routes.js"; import { inject } from "./infrastructure/di/injector.js"; import { sessionHandler } from "./infrastructure/sessionHandler.js"; import { EnvironmentService } from "./services/environmentService.js"; import { keycloak } from "./services/keycloak/user/index.js"; const app = express(); app.use(sessionHandler); app.use(keycloak.middleware()); app.use(express.urlencoded({ extended: true })); app.use(express.json()); app.use( cors({ origin: [ "https://taekwondo-chemnitz.toni714.de", "https://tcc-1-ev-intern.web.app", "http://localhost:4200", "https://localhost:4200", "http://localhost:3000", "http://localhost:8080", ], //TODO reevaluate }), ); // const dbService = inject(DatabaseService); // app.use(async (req, res, next) => { // await dbService.createTransaction(async prisma => { // (req as any).transaction = prisma; // return new Promise((resolve, reject) => { // res.on("finish", resolve); // res.on("close", resolve); // res.on("error", reject); // next(); // }); // }); // }); RegisterRoutes(app); const environment = inject(EnvironmentService); // wants to be last app.use((err: unknown, _req: Request, res: Response, _next: NextFunction) => { res.status(500); res.send(JSON.stringify(err)); throw err; }); if (environment.isDev()) { //TODO create self-signed for localhost const port = 3000; app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); }); } else { //TODO start with HTTPS in production } console.log("done");