dev env setup

This commit is contained in:
tw-blue
2025-12-06 21:27:29 +01:00
parent 987a380758
commit bc9f0f9f3b
38 changed files with 5953 additions and 733 deletions
+51 -4
View File
@@ -1,19 +1,66 @@
import express from "express";
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();
const port = 3000;
app.use(sessionHandler);
app.use(keycloak.middleware());
// console.log("not using", 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",
],
//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<void>((resolve, reject) => {
// res.on("finish", resolve);
// res.on("close", resolve);
// res.on("error", reject);
// next();
// });
// });
// });
RegisterRoutes(app);
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
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");