diff --git a/apps/api/v1/lib/helpers/checkIsInMaintenanceMode.ts b/apps/api/v1/lib/helpers/checkIsInMaintenanceMode.ts deleted file mode 100644 index 8f2f0879b3..0000000000 --- a/apps/api/v1/lib/helpers/checkIsInMaintenanceMode.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { get } from "@vercel/edge-config"; -import type { NextMiddleware } from "next-api-middleware"; - -const safeGet = async (key: string): Promise => { - try { - return get(key); - } catch (error) { - // Don't crash if EDGE_CONFIG env var is missing - } -}; - -export const config = { matcher: "/:path*" }; - -export const checkIsInMaintenanceMode: NextMiddleware = async (req, res, next) => { - const isInMaintenanceMode = await safeGet("isInMaintenanceMode"); - if (isInMaintenanceMode) { - return res - .status(503) - .json({ message: "API is currently under maintenance. Please try again at a later time." }); - } - - await next(); -}; diff --git a/apps/api/v1/lib/helpers/withMiddleware.ts b/apps/api/v1/lib/helpers/withMiddleware.ts index 3b06627ccc..ff409fba51 100644 --- a/apps/api/v1/lib/helpers/withMiddleware.ts +++ b/apps/api/v1/lib/helpers/withMiddleware.ts @@ -3,7 +3,6 @@ import { label } from "next-api-middleware"; import { addRequestId } from "./addRequestid"; import { captureErrors } from "./captureErrors"; import { captureUserId } from "./captureUserId"; -import { checkIsInMaintenanceMode } from "./checkIsInMaintenanceMode"; import { extendRequest } from "./extendRequest"; import { HTTP_DELETE, @@ -26,7 +25,6 @@ const middleware = { HTTP_POST, HTTP_DELETE, addRequestId, - checkIsInMaintenanceMode, verifyApiKey, rateLimitApiKey, extendRequest, @@ -38,16 +36,14 @@ const middleware = { type Middleware = keyof typeof middleware; -const middlewareOrder = [ - // The order here, determines the order of execution - "checkIsInMaintenanceMode", +const middlewareOrder: Middleware[] = [ "extendRequest", "captureErrors", "verifyApiKey", "rateLimitApiKey", "addRequestId", "captureUserId", -] as Middleware[]; // <-- Provide a list of middleware to call automatically +]; const withMiddleware = label(middleware, middlewareOrder);