Content-Length: 339058 | pFad | https://github.com/midwayjs/midway/commit/621a99a9ee77a8f370a28a395363f585057bd054

E1 fix: @Func decorator with empty metadata (#1137) · midwayjs/midway@621a99a · GitHub
Skip to content

Commit

Permalink
fix: @func decorator with empty metadata (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurten authored Jul 6, 2021
1 parent 5be4757 commit 621a99a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/util/webRouterCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ export class WebRouterCollector {
const data: RouterInfo = {
prefix,
routerName: '',
url: webRouter['path'] ?? '/',
url: webRouter['path'] ?? '',
requestMethod: webRouter['method'] ?? 'get',
method: webRouter['key'],
method: webRouter['key'] ?? '',
description: '',
summary: '',
handlerName: `${controllerId}.${webRouter['key']}`,
Expand All @@ -372,7 +372,7 @@ export class WebRouterCollector {
};
if (functionMeta) {
// get function information
data.functionName = controllerId + '-' + webRouter['key'];
data.functionName = controllerId + '-' + (webRouter['key'] ?? '');
data.functionTriggerName = ServerlessTriggerType.HTTP;
data.functionTriggerMetadata = {
path: webRouter['path'] ?? '/',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Provide, Func } from '@midwayjs/decorator';

@Provide()
@Func('index.handler', { middleware: ['bottleServiceMiddleware'] })
export class IndexHandler {
/**
* @param event
*/
async handler(event) {
return {
data: 'hello world'
};
}
}


@Provide()
export class IndexOneHandler {
/**
* @param event
*/
@Func('indexone.handler', { middleware: ['bottleServiceMiddleware'] })
async handlerone(event) {
return {
data: 'hello world one'
};
}

/**
* @param event
*/
@Func('indextwo.handler')
async handlertwo(event) {
return {
data: 'hello world two'
};
}
}
4 changes: 2 additions & 2 deletions packages/core/test/util/webRouterCollector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('/test/util/webRouterCollector.test.ts', function () {
clearContainerCache();
const collector = new WebRouterCollector(join(__dirname, '../fixtures/base-app-func-router'), { includeFunctionRouter: true});
const result = await collector.getFlattenRouterTable();
expect(result.length).toEqual(6);
expect(result.length).toEqual(8);
expect(matchObjectPropertyInArray(result, {
'controllerId': 'helloHttpService',
'funcHandlerName': 'helloHttpService.upload',
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('/test/util/webRouterCollector.test.ts', function () {

expect(matchObjectPropertyInArray(result, {
"prefix": "/",
"url": "/",
"url": "",
"requestMethod": "get",
"method": "upload",
"handlerName": "helloHttpService.upload",
Expand Down
2 changes: 1 addition & 1 deletion packages/faas/test/fixtures/base-app-new/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FunctionHandler } from '../../../../src';
})
export class HelloService implements FunctionHandler {
@Inject()
ctx; // context
ctx: any; // context

async handler(event) {
return event.text + this.ctx.text;
Expand Down

0 comments on commit 621a99a

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/midwayjs/midway/commit/621a99a9ee77a8f370a28a395363f585057bd054

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy