From 373203d7f03738a6a6dcfad53fc837d163118e4c Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Mon, 26 Feb 2024 09:46:24 +0800 Subject: [PATCH] fix(routes): prevent server crash --- docker-compose.dev.yml | 1 - package.json | 2 +- src/routes/formsg/formsgGGsRepair.ts | 4 ++++ src/routes/formsg/formsgSiteCreation.ts | 4 ++++ src/routes/formsg/formsgSiteLaunch.ts | 4 ++++ src/routes/v2/auth.js | 4 ++++ src/routes/v2/authenticated/collaborators.ts | 4 ++++ src/routes/v2/authenticated/index.js | 3 +++ src/routes/v2/authenticated/metrics.ts | 4 ++++ src/routes/v2/authenticated/netlifyToml.js | 4 ++++ src/routes/v2/authenticated/notifications.ts | 4 ++++ src/routes/v2/authenticated/review.ts | 4 ++++ src/routes/v2/authenticated/sites.ts | 4 ++++ src/routes/v2/authenticated/users.ts | 4 ++++ src/routes/v2/authenticatedSites/collectionPages.js | 3 +++ src/routes/v2/authenticatedSites/collections.js | 3 +++ src/routes/v2/authenticatedSites/contactUs.js | 4 +++- src/routes/v2/authenticatedSites/homepage.js | 3 +++ src/routes/v2/authenticatedSites/index.js | 3 +++ src/routes/v2/authenticatedSites/media.ts | 5 +++++ src/routes/v2/authenticatedSites/navigation.js | 4 +++- src/routes/v2/authenticatedSites/repoManagement.ts | 4 +++- src/routes/v2/authenticatedSites/resourceCategories.js | 3 +++ src/routes/v2/authenticatedSites/resourcePages.js | 3 +++ src/routes/v2/authenticatedSites/resourceRoom.js | 4 ++++ src/routes/v2/authenticatedSites/settings.js | 4 ++++ src/routes/v2/authenticatedSites/unlinkedPages.js | 4 ++++ src/routes/v2/sgidAuth.ts | 4 ++++ 28 files changed, 96 insertions(+), 5 deletions(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index ca47cfc96..f7f2e0bb3 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -12,7 +12,6 @@ services: - .env volumes: - ./:/opt/isomercms-backend - - /opt/isomercms-backend/node_modules - ${EFS_VOL_PATH}:${EFS_VOL_PATH} - "~/.gitconfig:/etc/gitconfig" diff --git a/package.json b/package.json index 202c3f047..ed8d4e47f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register -r dotenv/config build/server.js dotenv_config_path=/efs/isomer/.isomer.env", "start:ecs:prod": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register src/server.js", "start:ecs:staging": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register src/server.js", - "start::ecs:dev": "ts-node-dev --respawn src/server.js", + "start:ecs:dev": "ts-node-dev --respawn src/server.js", "dev": "source .env && docker compose -f docker-compose.dev.yml up", "test:docker": "docker run -d -p 54321:5432 --name postgres -e POSTGRES_USER=isomer -e POSTGRES_PASSWORD=password -e POSTGRES_DB=isomercms_test postgres:latest", "test": "source .env.test && jest --runInBand", diff --git a/src/routes/formsg/formsgGGsRepair.ts b/src/routes/formsg/formsgGGsRepair.ts index 2bf41a5e9..6d3fd8e7c 100644 --- a/src/routes/formsg/formsgGGsRepair.ts +++ b/src/routes/formsg/formsgGGsRepair.ts @@ -257,6 +257,10 @@ ${syncedRepos.map((repo) => `
  • ${repo}
  • `)} this.getGGsRepairFormSubmission ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/formsg/formsgSiteCreation.ts b/src/routes/formsg/formsgSiteCreation.ts index a202a22ef..6f5f3c3dd 100644 --- a/src/routes/formsg/formsgSiteCreation.ts +++ b/src/routes/formsg/formsgSiteCreation.ts @@ -183,6 +183,10 @@ export class FormsgSiteCreateRouter { this.formsgCreateSite ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/formsg/formsgSiteLaunch.ts b/src/routes/formsg/formsgSiteLaunch.ts index f4906f9fe..f6860fafb 100644 --- a/src/routes/formsg/formsgSiteLaunch.ts +++ b/src/routes/formsg/formsgSiteLaunch.ts @@ -349,6 +349,10 @@ export class FormsgSiteLaunchRouter { this.handleSiteLaunchFormRequest ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/auth.js b/src/routes/v2/auth.js index d439766e3..59727cde6 100644 --- a/src/routes/v2/auth.js +++ b/src/routes/v2/auth.js @@ -144,6 +144,10 @@ class AuthRouter { attachReadRouteHandlerWrapper(this.whoami) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticated/collaborators.ts b/src/routes/v2/authenticated/collaborators.ts index b507f8ff7..85b2adf09 100644 --- a/src/routes/v2/authenticated/collaborators.ts +++ b/src/routes/v2/authenticated/collaborators.ts @@ -175,6 +175,10 @@ export class CollaboratorsRouter { attachReadRouteHandlerWrapper(this.getCollaboratorsStatistics) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticated/index.js b/src/routes/v2/authenticated/index.js index 2df4dd80c..ef0641bd7 100644 --- a/src/routes/v2/authenticated/index.js +++ b/src/routes/v2/authenticated/index.js @@ -76,6 +76,9 @@ const getAuthenticatedSubrouter = ({ authenticatedSubrouter.use("/user", usersRouter.getRouter()) authenticatedSubrouter.use("/netlify-toml", netlifyTomlV2Router.getRouter()) + authenticatedSubrouter.use((_req, res, next) => { + next() + }) return authenticatedSubrouter } diff --git a/src/routes/v2/authenticated/metrics.ts b/src/routes/v2/authenticated/metrics.ts index 85ed99b34..8442076df 100644 --- a/src/routes/v2/authenticated/metrics.ts +++ b/src/routes/v2/authenticated/metrics.ts @@ -43,6 +43,10 @@ export class MetricsRouter { const router = express.Router({ mergeParams: true }) router.post("/feedback", this.collateUserFeedback) + + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticated/netlifyToml.js b/src/routes/v2/authenticated/netlifyToml.js index a65e6ce33..7611b8a42 100644 --- a/src/routes/v2/authenticated/netlifyToml.js +++ b/src/routes/v2/authenticated/netlifyToml.js @@ -26,6 +26,10 @@ class NetlifyTomlRouter { router.get("/", attachReadRouteHandlerWrapper(this.readNetlifyToml)) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticated/notifications.ts b/src/routes/v2/authenticated/notifications.ts index 832d54d4c..f100361f4 100644 --- a/src/routes/v2/authenticated/notifications.ts +++ b/src/routes/v2/authenticated/notifications.ts @@ -100,6 +100,10 @@ export class NotificationsRouter { attachWriteRouteHandlerWrapper(this.markNotificationsAsRead) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticated/review.ts b/src/routes/v2/authenticated/review.ts index aa8f4250c..d4923124a 100644 --- a/src/routes/v2/authenticated/review.ts +++ b/src/routes/v2/authenticated/review.ts @@ -1408,6 +1408,10 @@ export class ReviewsRouter { attachReadRouteHandlerWrapper(this.closeReviewRequest) ) router.get("/:requestId/blob", attachReadRouteHandlerWrapper(this.getBlob)) + + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticated/sites.ts b/src/routes/v2/authenticated/sites.ts index b7b800dbd..61b34c464 100644 --- a/src/routes/v2/authenticated/sites.ts +++ b/src/routes/v2/authenticated/sites.ts @@ -254,6 +254,10 @@ export class SitesRouter { // and endpoint can be changed to GET. router.post("/preview", attachReadRouteHandlerWrapper(this.getPreviewInfo)) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticated/users.ts b/src/routes/v2/authenticated/users.ts index 2a8afafe0..cb79f12f6 100644 --- a/src/routes/v2/authenticated/users.ts +++ b/src/routes/v2/authenticated/users.ts @@ -132,6 +132,10 @@ export class UsersRouter { attachReadRouteHandlerWrapper(this.verifyMobileNumberOtp) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticatedSites/collectionPages.js b/src/routes/v2/authenticatedSites/collectionPages.js index 7487b6e0f..a0568939f 100644 --- a/src/routes/v2/authenticatedSites/collectionPages.js +++ b/src/routes/v2/authenticatedSites/collectionPages.js @@ -224,6 +224,9 @@ class CollectionPagesRouter { attachRollbackRouteHandlerWrapper(this.deleteCollectionPage) ) + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/collections.js b/src/routes/v2/authenticatedSites/collections.js index 618825c07..af6cba6d6 100644 --- a/src/routes/v2/authenticatedSites/collections.js +++ b/src/routes/v2/authenticatedSites/collections.js @@ -271,6 +271,9 @@ class CollectionsRouter { attachRollbackRouteHandlerWrapper(this.moveCollectionDirectoryPages) ) + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/contactUs.js b/src/routes/v2/authenticatedSites/contactUs.js index 2da7c57dc..0e73bc2d9 100644 --- a/src/routes/v2/authenticatedSites/contactUs.js +++ b/src/routes/v2/authenticatedSites/contactUs.js @@ -54,7 +54,9 @@ class ContactUsRouter { router.get("/", attachReadRouteHandlerWrapper(this.readContactUs)) router.post("/", attachRollbackRouteHandlerWrapper(this.updateContactUs)) - + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/homepage.js b/src/routes/v2/authenticatedSites/homepage.js index fa6c982b9..d966e3b60 100644 --- a/src/routes/v2/authenticatedSites/homepage.js +++ b/src/routes/v2/authenticatedSites/homepage.js @@ -59,6 +59,9 @@ class HomepageRouter { router.get("/", attachReadRouteHandlerWrapper(this.readHomepage)) router.post("/", attachRollbackRouteHandlerWrapper(this.updateHomepage)) + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/index.js b/src/routes/v2/authenticatedSites/index.js index 995a0953d..33ace93fd 100644 --- a/src/routes/v2/authenticatedSites/index.js +++ b/src/routes/v2/authenticatedSites/index.js @@ -240,6 +240,9 @@ const getAuthenticatedSitesSubrouter = ({ authenticatedSitesSubrouter.use("/settings", settingsV2Router.getRouter()) authenticatedSitesSubrouter.use("/admin", repoManagementV2Router.getRouter()) authenticatedSitesSubrouter.use(notificationOnEditHandler.createNotification) + authenticatedSitesSubrouter.use((_req, res, next) => { + next() + }) return authenticatedSitesSubrouter } diff --git a/src/routes/v2/authenticatedSites/media.ts b/src/routes/v2/authenticatedSites/media.ts index 3d09d9e87..06dfda9a0 100644 --- a/src/routes/v2/authenticatedSites/media.ts +++ b/src/routes/v2/authenticatedSites/media.ts @@ -83,6 +83,7 @@ export class MediaRouter { { page: number; limit: number; search: string }, { userWithSiteSessionData: UserWithSiteSessionData } > = async (req, res) => { + console.log("in listMediaDirectoryFiles") const { userWithSiteSessionData } = res.locals const { directoryName } = req.params @@ -445,6 +446,10 @@ export class MediaRouter { attachRollbackRouteHandlerWrapper(this.deleteMediaFile) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticatedSites/navigation.js b/src/routes/v2/authenticatedSites/navigation.js index 0092fa1b8..f6fd3f415 100644 --- a/src/routes/v2/authenticatedSites/navigation.js +++ b/src/routes/v2/authenticatedSites/navigation.js @@ -53,7 +53,9 @@ class NavigationRouter { router.get("/", attachReadRouteHandlerWrapper(this.readNavigation)) router.post("/", attachRollbackRouteHandlerWrapper(this.updateNavigation)) - + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/repoManagement.ts b/src/routes/v2/authenticatedSites/repoManagement.ts index 7d2a4d539..c0d3283ac 100644 --- a/src/routes/v2/authenticatedSites/repoManagement.ts +++ b/src/routes/v2/authenticatedSites/repoManagement.ts @@ -65,7 +65,9 @@ export class RepoManagementRouter { router.use(this.authorizationMiddleware.verifySiteMember) router.post("/resetRepo", attachWriteRouteHandlerWrapper(this.resetRepo)) - + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/resourceCategories.js b/src/routes/v2/authenticatedSites/resourceCategories.js index 19dce7207..b18cb1891 100644 --- a/src/routes/v2/authenticatedSites/resourceCategories.js +++ b/src/routes/v2/authenticatedSites/resourceCategories.js @@ -142,6 +142,9 @@ class ResourceCategoriesRouter { attachRollbackRouteHandlerWrapper(this.moveResourceDirectoryPages) ) + router.use((_req, res, next) => { + next() + }) return router } } diff --git a/src/routes/v2/authenticatedSites/resourcePages.js b/src/routes/v2/authenticatedSites/resourcePages.js index c4111e1bf..16bd6d78e 100644 --- a/src/routes/v2/authenticatedSites/resourcePages.js +++ b/src/routes/v2/authenticatedSites/resourcePages.js @@ -144,6 +144,9 @@ class ResourcePagesRouter { "/:pageName", attachRollbackRouteHandlerWrapper(this.deleteResourcePage) ) + router.use((_req, res, next) => { + next() + }) return router } diff --git a/src/routes/v2/authenticatedSites/resourceRoom.js b/src/routes/v2/authenticatedSites/resourceRoom.js index 1e66d7371..525a05ff4 100644 --- a/src/routes/v2/authenticatedSites/resourceRoom.js +++ b/src/routes/v2/authenticatedSites/resourceRoom.js @@ -125,6 +125,10 @@ class ResourceRoomRouter { attachRollbackRouteHandlerWrapper(this.deleteResourceRoomDirectory) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticatedSites/settings.js b/src/routes/v2/authenticatedSites/settings.js index 4005a3977..ea11b44a6 100644 --- a/src/routes/v2/authenticatedSites/settings.js +++ b/src/routes/v2/authenticatedSites/settings.js @@ -139,6 +139,10 @@ class SettingsRouter { attachWriteRouteHandlerWrapper(this.updateRepoPassword) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/authenticatedSites/unlinkedPages.js b/src/routes/v2/authenticatedSites/unlinkedPages.js index 0b82a7ca6..a4064fe9d 100644 --- a/src/routes/v2/authenticatedSites/unlinkedPages.js +++ b/src/routes/v2/authenticatedSites/unlinkedPages.js @@ -175,6 +175,10 @@ class UnlinkedPagesRouter { attachRollbackRouteHandlerWrapper(this.moveUnlinkedPages) ) + router.use((_req, res, next) => { + next() + }) + return router } } diff --git a/src/routes/v2/sgidAuth.ts b/src/routes/v2/sgidAuth.ts index 4ff12c64b..a45388905 100644 --- a/src/routes/v2/sgidAuth.ts +++ b/src/routes/v2/sgidAuth.ts @@ -251,6 +251,10 @@ export class SgidAuthRouter { attachReadRouteHandlerWrapper(this.handleSgidMultiuserLogin) ) + router.use((_req, res, next) => { + next() + }) + return router } }