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 {
165
165
// This causes a double action execution on our side, which results in an unhandled rejection,
166
166
// saying: "Can't set headers after they are sent".
167
167
// 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 )
169
169
return next ( ) ;
170
170
171
171
return executeCallback ( { request, response, next} ) ;
@@ -207,7 +207,7 @@ export class ExpressDriver extends BaseDriver {
207
207
208
208
case "session-param" :
209
209
return request . session [ param . name ] ;
210
-
210
+
211
211
case "session" :
212
212
return request . session ;
213
213
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {importClassesFromDirectories} from "./util/importClassesFromDirectories"
14
14
15
15
export * from "./container" ;
16
16
17
+ export * from "./decorator/All" ;
17
18
export * from "./decorator/Authorized" ;
18
19
export * from "./decorator/Body" ;
19
20
export * from "./decorator/BodyParam" ;
Original file line number Diff line number Diff line change 1
1
/**
2
2
* Controller action type.
3
3
*/
4
- export type ActionType = "checkout"
4
+ export type ActionType = "all"
5
+ | "checkout"
5
6
| "connect"
6
7
| "copy"
7
8
| "delete"
@@ -26,4 +27,4 @@ export type ActionType = "checkout"
26
27
| "subscribe"
27
28
| "trace"
28
29
| "unlock"
29
- | "unsubscribe" ;
30
+ | "unsubscribe" ;
You can’t perform that action at this time.
0 commit comments