UNPKG

@sapphire/plugin-api

Version:

Plugin for @sapphire/framework to expose a REST API

30 lines (27 loc) 1.17 kB
'use strict'; var HttpCodes_cjs = require('../lib/structures/http/HttpCodes.cjs'); var Middleware_cjs = require('../lib/structures/Middleware.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.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_cjs.HttpCodes.PayloadTooLarge).json({ error: "Exceeded maximum content length." }); } } }; __name(_PluginMiddleware, "PluginMiddleware"); var PluginMiddleware = _PluginMiddleware; exports.PluginMiddleware = PluginMiddleware; //# sourceMappingURL=body.cjs.map //# sourceMappingURL=body.cjs.map