Files
SnowLuma/.pnpm-store/v11/files/2f/acd0460f1edae857d2a2a59a09fe6fb39ca121bfd6f17f54936a7c5e8b193e32225cf16f09b33343124a10be81a75e3896773e3d07e56631265146196b1b2b
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

18 lines
777 B
Plaintext

import { MethodNotAllowedError } from '../errors.js';
/**
* Middleware to handle unsupported HTTP methods with a 405 Method Not Allowed response.
*
* @param allowedMethods Array of allowed HTTP methods for this endpoint (e.g., ['GET', 'POST'])
* @returns Express middleware that returns a 405 error if method not in allowed list
*/
export function allowedMethods(allowedMethods) {
return (req, res, next) => {
if (allowedMethods.includes(req.method)) {
next();
return;
}
const error = new MethodNotAllowedError(`The method ${req.method} is not allowed for this endpoint`);
res.status(405).set('Allow', allowedMethods.join(', ')).json(error.toResponseObject());
};
}
//# sourceMappingURL=allowedMethods.js.map