Comparing version 2.2.2 to 2.2.3
@@ -33,3 +33,3 @@ "use strict"; | ||
const filesystem_1 = require("./util/filesystem"); | ||
const body_parser_1 = require("./middleware/body-parser"); | ||
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser")); | ||
/** | ||
@@ -51,5 +51,11 @@ * Creates a router at the specified port & hostname, sourcing | ||
for (const { internalHandler, method, middleware, accept } of controller) { | ||
const enableTypes = accept || []; | ||
const { pre = [], post = [] } = middleware || {}; | ||
const parsingMiddleware = accept | ||
? [body_parser_1.handleParseError, (0, body_parser_1.bodyParser)({ enableTypes: accept })] | ||
const parsingMiddleware = enableTypes.length | ||
? [ | ||
(0, koa_bodyparser_1.default)({ | ||
enableTypes: accept, | ||
onerror: (_error, context) => context.throw(422), | ||
}), | ||
] | ||
: []; | ||
@@ -56,0 +62,0 @@ const middlewareChain = [ |
import Koa, { Next } from "koa"; | ||
import Router from "koa-router"; | ||
import { mapDirectoryToRoutes } from "@/util/filesystem"; | ||
import { handleParseError, bodyParser } from "@/middleware/body-parser"; | ||
import { ExtendedContext } from "@/@types/http-method"; | ||
import { ParsedRouteController } from "@/@types/route-controller"; | ||
import bodyParser from "koa-bodyparser"; | ||
@@ -41,5 +41,12 @@ interface CreateRouterParams { | ||
for (const { internalHandler, method, middleware, accept } of controller) { | ||
const enableTypes: string[] = accept || []; | ||
const { pre = [], post = [] } = middleware || {}; | ||
const parsingMiddleware = accept | ||
? [handleParseError, bodyParser({ enableTypes: accept })] | ||
const parsingMiddleware = enableTypes.length | ||
? [ | ||
bodyParser({ | ||
enableTypes: accept, | ||
onerror: (_error, context) => context.throw(422), | ||
}), | ||
] | ||
: []; | ||
@@ -46,0 +53,0 @@ |
{ | ||
"name": "18h", | ||
"description": "A Next.js style dynamic API router for Koa-based APIs.", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "https://github.com/ridafkih/18h" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29397
25
616