routing-controllers
Advanced tools
Comparing version 0.9.0-alpha.1 to 0.9.0-alpha.2
@@ -169,14 +169,22 @@ "use strict"; | ||
var routeHandler = function routeHandler(request, response, next) { | ||
// Express calls the "get" route automatically when we call the "head" route: | ||
// Reference: https://expressjs.com/en/4x/api.html#router.METHOD | ||
// This causes a double action execution on our side, which results in an unhandled rejection, | ||
// saying: "Can't set headers after they are sent". | ||
// The following line skips action processing when the request method does not match the action method. | ||
if (actionMetadata.type !== "all" && request.method.toLowerCase() !== actionMetadata.type) | ||
return next(); | ||
return executeCallback({ request: request, response: response, next: next }); | ||
}; | ||
// This ensures that a request is only processed once to prevent unhandled rejections saying | ||
// "Can't set headers after they are sent" | ||
// Some examples of reasons a request may cause multiple route calls: | ||
// * Express calls the "get" route automatically when we call the "head" route: | ||
// Reference: https://expressjs.com/en/4x/api.html#router.METHOD | ||
// This causes a double execution on our side. | ||
// * Multiple routes match the request (e.g. GET /users/me matches both @All(/users/me) and @Get(/users/:id)). | ||
// The following middleware only starts an action processing if the request has not been processed before. | ||
var routeGuard = function routeGuard(request, response, next) { | ||
if (!request.routingControllersStarted) { | ||
request.routingControllersStarted = true; | ||
return next(); | ||
} | ||
}; | ||
// finally register action in express | ||
(_a = this.express)[actionMetadata.type.toLowerCase()].apply(_a, __spreadArrays([ | ||
route | ||
route, | ||
routeGuard | ||
], beforeMiddlewares, defaultMiddlewares, [ | ||
@@ -183,0 +191,0 @@ routeHandler |
@@ -179,5 +179,16 @@ "use strict"; | ||
}; | ||
// This ensures that a request is only processed once. Multiple routes may match a request | ||
// e.g. GET /users/me matches both @All(/users/me) and @Get(/users/:id)), only the first matching route should | ||
// be called. | ||
// The following middleware only starts an action processing if the request has not been processed before. | ||
var routeGuard = function (context, next) { | ||
if (!context.request.routingControllersStarted) { | ||
context.request.routingControllersStarted = true; | ||
return next(); | ||
} | ||
}; | ||
// finally register action in koa | ||
(_a = this.router)[actionMetadata.type.toLowerCase()].apply(_a, __spreadArrays([ | ||
route | ||
route, | ||
routeGuard | ||
], beforeMiddlewares, defaultMiddlewares, [ | ||
@@ -184,0 +195,0 @@ routeHandler |
@@ -43,2 +43,3 @@ import { CustomParameterDecorator } from "./CustomParameterDecorator"; | ||
export * from "./decorator/Session"; | ||
export * from "./decorator/SessionParam"; | ||
export * from "./decorator/State"; | ||
@@ -45,0 +46,0 @@ export * from "./decorator/UploadedFile"; |
@@ -52,2 +52,3 @@ "use strict"; | ||
__export(require("./decorator/Session")); | ||
__export(require("./decorator/SessionParam")); | ||
__export(require("./decorator/State")); | ||
@@ -54,0 +55,0 @@ __export(require("./decorator/UploadedFile")); |
{ | ||
"name": "routing-controllers", | ||
"private": false, | ||
"version": "0.9.0-alpha.1", | ||
"version": "0.9.0-alpha.2", | ||
"description": "Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage for Express / Koa using TypeScript.", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
402640
5925