Skip to content

Commit 311f2fb

Browse files
committed
Merge branch 'master' of https://github.com/Elassyo/routing-controllers into Elassyo-master
2 parents 09a6d6a + 8e36754 commit 311f2fb

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ There are set of prepared errors you can use:
733733
* UnauthorizedError
734734

735735

736-
You can also create and use your own errors by extending `HttpError` class.
736+
You can also create and use your own errors by extending `HttpError` class.
737737
To define the data returned to the client, you could define a toJSON method in your error.
738738

739739
```typescript
@@ -755,7 +755,7 @@ class DbError extends HttpError {
755755
}
756756
}
757757
}
758-
```
758+
```
759759

760760
#### Enable CORS
761761

@@ -796,7 +796,7 @@ app.listen(3000);
796796

797797
#### Default settings
798798

799-
You can override default status code in routing-controllers options.
799+
You can override default status code in routing-controllers options.
800800

801801
```typescript
802802
import "reflect-metadata";
@@ -809,9 +809,9 @@ const app = createExpressServer({
809809
//with this option, null will return 404 by default
810810
nullResultCode: 404,
811811

812-
//with this option, void or Promise<void> will return 204 by default
812+
//with this option, void or Promise<void> will return 204 by default
813813
undefinedResultCode: 204,
814-
814+
815815
paramOptions: {
816816
//with this option, argument will be required by default
817817
required: true
@@ -1486,7 +1486,8 @@ export class QuestionController {
14861486
| `@Patch(route: string\|RegExp)` | `@Patch("/users/:id") patch()` | Methods marked with this decorator will register a request made with PATCH HTTP Method to a given route. In action options you can specify if action should response json or regular text response. | `app.patch("/users/:id", patch)` |
14871487
| `@Delete(route: string\|RegExp)` | `@Delete("/users/:id") delete()` | Methods marked with this decorator will register a request made with DELETE HTTP Method to a given route. In action options you can specify if action should response json or regular text response. | `app.delete("/users/:id", delete)` |
14881488
| `@Head(route: string\|RegExp)` | `@Head("/users/:id") head()` | Methods marked with this decorator will register a request made with HEAD HTTP Method to a given route. In action options you can specify if action should response json or regular text response. | `app.head("/users/:id", head)` |
1489-
| `@Method(methodName: string, route: string\|RegExp)` | `@Method("move", "/users/:id") move()` | Methods marked with this decorator will register a request made with given `methodName` HTTP Method to a given route. In action options you can specify if action should response json or regular text response. | `app.move("/users/:id", move)` |
1489+
| `@All(route: string\|RegExp)` | `@All("/users/me") rewrite()` | Methods marked with this decorator will register a request made with any HTTP Method to a given route. In action options you can specify if action should response json or regular text response. | `app.all("/users/me", rewrite)` |
1490+
| `@Method(methodName: string, route: string\|RegExp)` | `@Method("move", "/users/:id") move()` | Methods marked with this decorator will register a request made with given `methodName` HTTP Method to a given route. In action options you can specify if action should response json or regular text response. | `app.move("/users/:id", move)` |
14901491

14911492
#### Method Parameter Decorators
14921493

src/decorator/All.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

src/driver/express/ExpressDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {importClassesFromDirectories} from "./util/importClassesFromDirectories"
1414

1515
export * from "./container";
1616

17+
export * from "./decorator/All";
1718
export * from "./decorator/Authorized";
1819
export * from "./decorator/Body";
1920
export * from "./decorator/BodyParam";

src/metadata/types/ActionType.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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";

0 commit comments

Comments
 (0)