2024-05-15 19:56:22 +00:00
|
|
|
import { AuthRouter } from "@/contexts/auth";
|
|
|
|
|
import { CatalogRouter } from "@/contexts/catalog";
|
2024-05-19 22:04:23 +00:00
|
|
|
import { createMiddlewareMap } from "@/contexts/common/infrastructure/express";
|
2024-05-16 18:16:00 +00:00
|
|
|
import { UserRouter } from "@/contexts/users";
|
2024-05-15 19:56:22 +00:00
|
|
|
import Express from "express";
|
2024-05-19 22:04:23 +00:00
|
|
|
import { createContextMiddleware } from "./context.middleware";
|
2024-04-23 15:29:38 +00:00
|
|
|
|
2024-05-15 19:56:22 +00:00
|
|
|
export const v1Routes = () => {
|
|
|
|
|
const routes = Express.Router({ mergeParams: true });
|
2024-04-23 15:29:38 +00:00
|
|
|
|
2024-05-15 19:56:22 +00:00
|
|
|
routes.get("/hello", (req, res) => {
|
|
|
|
|
res.send("Hello world!");
|
|
|
|
|
});
|
2024-04-23 15:29:38 +00:00
|
|
|
|
2024-05-15 19:56:22 +00:00
|
|
|
routes.use(
|
|
|
|
|
(
|
|
|
|
|
req: Express.Request,
|
|
|
|
|
res: Express.Response,
|
|
|
|
|
next: Express.NextFunction,
|
|
|
|
|
) => {
|
2024-05-19 22:04:23 +00:00
|
|
|
res.locals["context"] = createContextMiddleware();
|
|
|
|
|
res.locals["middlewares"] = createMiddlewareMap();
|
2024-05-15 19:56:22 +00:00
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
routes.use((req, res, next) => {
|
|
|
|
|
console.log(
|
|
|
|
|
`[${new Date().toLocaleTimeString()}] Incoming request to ${req.path}`,
|
|
|
|
|
);
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AuthRouter(routes);
|
2024-05-16 18:16:00 +00:00
|
|
|
UserRouter(routes);
|
2024-05-15 19:56:22 +00:00
|
|
|
CatalogRouter(routes);
|
|
|
|
|
|
|
|
|
|
return routes;
|
|
|
|
|
};
|