File tree Expand file tree Collapse file tree 4 files changed +34
-4
lines changed Expand file tree Collapse file tree 4 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1+ import { getMetadataArgsStorage } from "../index" ;
2+
3+ /**
4+ * Registers an action to be executed when a request comes on a given route.
5+ * Must be applied on a controller action.
6+ */
7+ export function All ( route ?: RegExp ) : Function ;
8+
9+ /**
10+ * Registers an action to be executed when a request comes on a given route.
11+ * Must be applied on a controller action.
12+ */
13+ export function All ( route ?: string ) : Function ;
14+
15+ /**
16+ * Registers an action to be executed when a request comes on a given route.
17+ * Must be applied on a controller action.
18+ */
19+ export function All ( route ?: string | RegExp ) : Function {
20+ return function ( object : Object , methodName : string ) {
21+ getMetadataArgsStorage ( ) . actions . push ( {
22+ type : "all" ,
23+ target : object . constructor ,
24+ method : methodName ,
25+ route : route
26+ } ) ;
27+ } ;
28+ }
Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ export class ExpressDriver extends BaseDriver {
165165 // This causes a double action execution on our side, which results in an unhandled rejection,
166166 // saying: "Can't set headers after they are sent".
167167 // The following line skips action processing when the request method does not match the action method.
168- if ( request . method . toLowerCase ( ) !== actionMetadata . type )
168+ if ( actionMetadata . type !== "all" && request . method . toLowerCase ( ) !== actionMetadata . type )
169169 return next ( ) ;
170170
171171 return executeCallback ( { request, response, next} ) ;
@@ -207,7 +207,7 @@ export class ExpressDriver extends BaseDriver {
207207
208208 case "session-param" :
209209 return request . session [ param . name ] ;
210-
210+
211211 case "session" :
212212 return request . session ;
213213
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {importClassesFromDirectories} from "./util/importClassesFromDirectories"
1414
1515export * from "./container" ;
1616
17+ export * from "./decorator/All" ;
1718export * from "./decorator/Authorized" ;
1819export * from "./decorator/Body" ;
1920export * from "./decorator/BodyParam" ;
Original file line number Diff line number Diff line change 11/**
22 * Controller action type.
33 */
4- export type ActionType = "checkout"
4+ export type ActionType = "all"
5+ | "checkout"
56 | "connect"
67 | "copy"
78 | "delete"
@@ -26,4 +27,4 @@ export type ActionType = "checkout"
2627 | "subscribe"
2728 | "trace"
2829 | "unlock"
29- | "unsubscribe" ;
30+ | "unsubscribe" ;
You can’t perform that action at this time.
0 commit comments