Skip to content

Commit 3886182

Browse files
committed
Fixed double action execution when processing HEAD routes
Signed-off-by: Fábio Batista <[email protected]>
1 parent 8ec4fa1 commit 3886182

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/driver/express/ExpressDriver.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ export class ExpressDriver extends BaseDriver {
150150
// prepare route and route handler function
151151
const route = ActionMetadata.appendBaseRoute(this.routePrefix, actionMetadata.fullRoute);
152152
const routeHandler = function routeHandler(request: any, response: any, next: Function) {
153+
// Express calls the "get" route automatically when we call the "head" route:
154+
// Reference: https://expressjs.com/en/4x/api.html#router.METHOD
155+
// This causes a double action execution on our side, which results in an unhandled rejection,
156+
// saying: "Can't set headers after they are sent".
157+
// The following line skips action processing when the request method does not match the action method.
158+
if (request.method.toLowerCase() !== actionMetadata.type)
159+
return next();
160+
153161
return executeCallback({request, response, next});
154162
};
155163

0 commit comments

Comments
 (0)