Skip to content

Commit

Permalink
feat: add setupRoutes on app
Browse files Browse the repository at this point in the history
  • Loading branch information
Williancc1557 committed Jul 24, 2022
1 parent e5d5c0b commit a011128
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"express": "^4.18.1",
"fast-glob": "^3.2.11",
"jsonwebtoken": "^8.5.1",
"mongodb": "^4.8.0",
"pino": "^8.3.0",
Expand Down
2 changes: 2 additions & 0 deletions src/main/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import express from "express";
import { setupMiddlewares } from "./middlewares";
import { setupRoutes } from "./routes";

const app = express();

setupMiddlewares(app);
setupRoutes(app);

export default app;
13 changes: 13 additions & 0 deletions src/main/config/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Express } from "express";
import { Router } from "express";
import fg from "fast-glob";

export const setupRoutes = (app: Express) => {
const router = Router();

app.use("/api", router);

fg.sync("**/src/main/routes/**routes.ts").map(async (file) => {
(await import(`../../../${file}`)).default(router);
});
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ fast-diff@^1.1.2:
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==

fast-glob@^3.2.9:
fast-glob@^3.2.11, fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
Expand Down

0 comments on commit a011128

Please sign in to comment.