UNPKG

@sapphire/plugin-api

Version:

Plugin for @sapphire/framework to expose a REST API

27 lines (25 loc) 1.02 kB
import { __name } from '../chunk-S573YWRP.mjs'; import { HttpCodes } from '../lib/structures/http/HttpCodes.mjs'; import { Middleware } from '../lib/structures/Middleware.mjs'; var _PluginMiddleware = class _PluginMiddleware extends Middleware { constructor(context) { super(context, { position: 20 }); } run(request, response) { if (!request.route) return; const contentType = request.headers["content-type"]; if (typeof contentType !== "string") return; const lengthString = request.headers["content-length"]; if (typeof lengthString !== "string") return; const length = Number(lengthString); const maximumLength = request.route.maximumBodyLength; if (length > maximumLength) { response.status(HttpCodes.PayloadTooLarge).json({ error: "Exceeded maximum content length." }); } } }; __name(_PluginMiddleware, "PluginMiddleware"); var PluginMiddleware = _PluginMiddleware; export { PluginMiddleware }; //# sourceMappingURL=body.mjs.map //# sourceMappingURL=body.mjs.map