refactor(routes): routes to modules + feat(auth): auth middleware basic structure done

This commit is contained in:
2024-10-27 20:08:42 +01:00
parent 946c2f3c56
commit 620b98c465
15 changed files with 96 additions and 12 deletions

View File

@@ -1,7 +1,8 @@
import express from "express";
import config from "./config";
import cors from "cors";
import { routes } from "./routes";
import { routes } from "./modules";
import { authorizationMiddleware } from "./modules/auth/auth.middleware";
const app = express();
const port = config.port;
@@ -12,6 +13,7 @@ if (config.enableCors) {
app.use(express.json());
// Global middleware
app.use(authorizationMiddleware as any);
app.use((req, _res, next) => {
console.log(`LOG: new ${req.method} request for ${req.url}`);
next();
@@ -23,7 +25,7 @@ app.use("/example", (req, _res, next) => {
next();
});
app.use("/api/v1", routes); // / serves as the base for the imported routes
app.use(config.baseRoute, routes); // / serves as the base for the imported routes
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);