feat: API Middleware

This commit is contained in:
Br0wnHammer committed 2026-02-20 00:31:42 +05:30
1 parent b87fd5438e
commit 600c937062
1 file changed
+6 -3
+6 -3
View File
@@ -6,18 +6,21 @@ class StatusPageRoutes {
private router: Router; private router: Router;
private statusPageController: any; private statusPageController: any;
constructor(statusPageController: any, verifyJWT: RequestHandler) { constructor(statusPageController: any, verifyJWT: RequestHandler, verifyStatusPageAccess: RequestHandler) {
this.router = Router(); this.router = Router();
this.statusPageController = statusPageController; this.statusPageController = statusPageController;
this.initRoutes(verifyJWT); this.initRoutes(verifyJWT, verifyStatusPageAccess);
} }
initRoutes(verifyJWT: RequestHandler) { initRoutes(verifyJWT: RequestHandler, verifyStatusPageAccess: RequestHandler) {
this.router.get("/team", verifyJWT, this.statusPageController.getStatusPagesByTeamId); this.router.get("/team", verifyJWT, this.statusPageController.getStatusPagesByTeamId);
this.router.post("/", upload.single("logo"), verifyJWT, this.statusPageController.createStatusPage); this.router.post("/", upload.single("logo"), verifyJWT, this.statusPageController.createStatusPage);
this.router.put("/:id", upload.single("logo"), verifyJWT, this.statusPageController.updateStatusPage); this.router.put("/:id", upload.single("logo"), verifyJWT, this.statusPageController.updateStatusPage);
// Route 1: published pages — no JWT
this.router.get("/:url", verifyStatusPageAccess, this.statusPageController.getStatusPageByUrl);
// Route 2: unpublished pages — JWT required (reached via next("route"))
this.router.get("/:url", verifyJWT, this.statusPageController.getStatusPageByUrl); this.router.get("/:url", verifyJWT, this.statusPageController.getStatusPageByUrl);
this.router.delete("/:id", verifyJWT, this.statusPageController.deleteStatusPage); this.router.delete("/:id", verifyJWT, this.statusPageController.deleteStatusPage);
} }