2024-05-15 19:56:22 +00:00
|
|
|
import { AuthRouter } from "@/contexts/auth";
|
|
|
|
|
import { CatalogRouter } from "@/contexts/catalog";
|
|
|
|
|
import { RepositoryManager } from "@/contexts/common/domain";
|
|
|
|
|
import { createSequelizeAdapter } from "@/contexts/common/infrastructure/sequelize";
|
|
|
|
|
import Express from "express";
|
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
|
|
|
//v1Routes.use("/auth", authRoutes);
|
|
|
|
|
//v1Routes.use("/catalog", catalogRoutes);
|
2024-04-23 17:19:41 +00:00
|
|
|
|
2024-05-15 19:56:22 +00:00
|
|
|
routes.use(
|
|
|
|
|
(
|
|
|
|
|
req: Express.Request,
|
|
|
|
|
res: Express.Response,
|
|
|
|
|
next: Express.NextFunction,
|
|
|
|
|
) => {
|
|
|
|
|
res.locals["context"] = {
|
|
|
|
|
adapter: createSequelizeAdapter(),
|
|
|
|
|
repositoryManager: RepositoryManager.getInstance(),
|
|
|
|
|
services: {},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.locals["middlewares"] = new Map<string, Express.RequestHandler>();
|
|
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
routes.use((req, res, next) => {
|
|
|
|
|
console.log(
|
|
|
|
|
`[${new Date().toLocaleTimeString()}] Incoming request to ${req.path}`,
|
|
|
|
|
);
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AuthRouter(routes);
|
|
|
|
|
CatalogRouter(routes);
|
|
|
|
|
|
|
|
|
|
return routes;
|
|
|
|
|
};
|