Files
medusa-store/packages/medusa/src/api/utils/unless-path.ts
T
Adrien de Peretti f81652bf6e chore(framework): Move and improve routes loader (#8392)
* chore(framework): Move and improve routes loader

* cleanup

* fix(framework): import
2024-08-01 16:18:42 +02:00

16 lines
780 B
TypeScript

import { NextFunction } from "express"
import { MedusaRequest, MedusaResponse } from "../../types/routing"
import { MiddlewareFunction } from "@medusajs/framework"
// Due to how our route loader works, where we load all middlewares before routes, ambiguous routes end up having all middlewares on different routes executed before the route handler is.
// This function allows us to skip middlewares for particular routes, so we can temporarily solve this without completely breaking the route loader for everyone.
export const unlessPath =
(onPath: RegExp, middleware: MiddlewareFunction) =>
(req: MedusaRequest, res: MedusaResponse, next: NextFunction) => {
if (onPath.test(req.path)) {
return next()
} else {
return middleware(req, res, next)
}
}