Skip to content

Commit

Permalink
fix: change all requestMethod to real method for serverless http requ…
Browse files Browse the repository at this point in the history
…est (#1028)
  • Loading branch information
czy88840616 authored May 7, 2021
1 parent ae242c1 commit 23e2943
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion packages/core/src/util/triggerCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ import { WebRouterCollector } from './webRouterCollector';
export class ServerlessTriggerCollector extends WebRouterCollector {
protected async analyze() {
this.options.includeFunctionRouter = true;
return super.analyze();
await super.analyze();
// requestMethod all transform to other method
for (const routerInfo of this.routes.values()) {
for (const info of routerInfo) {
if (info.requestMethod === 'all') {
info.functionTriggerMetadata.method = [
'get',
'post',
'put',
'delete',
'head',
'patch',
'options',
];
}
}
}
}

protected collectRoute(module) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/webRouterCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface RouterCollectorOptions {
export class WebRouterCollector {
protected readonly baseDir: string;
private isReady = false;
private routes = new Map<string, RouterInfo[]>();
protected routes = new Map<string, RouterInfo[]>();
private routesPriority: RouterPriority[] = [];
protected options: RouterCollectorOptions;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/util/triggerCollector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('/test/util/triggerCollector.test.ts', function () {
"funcHandlerName": "http.handler",
"functionName": "helloHttpService-handler",
"functionTriggerMetadata": {
"method": "all",
"method": ['get', 'post', 'put', 'delete', 'head', 'patch', 'options'],
"path": "/other"
},
"functionTriggerName": "http",
Expand Down

0 comments on commit 23e2943

Please sign in to comment.