@@ -3,7 +3,6 @@ import KoaRouter from 'koa-router';
33import { Context } from 'egg' ;
44import {
55 EggContext ,
6- HostType ,
76 HTTPControllerMeta ,
87 HTTPMethodMeta ,
98 HTTPParamType ,
@@ -50,22 +49,15 @@ export class HTTPMethodRegister {
5049 this . eggContainerFactory = eggContainerFactory ;
5150 }
5251
53- private hostMatch ( host : HostType | undefined , target : string ) {
54- if ( Array . isArray ( host ) ) {
55- return host . includes ( target ) ;
56- }
57- return host === target ;
58- }
59-
60- private createHandler ( methodMeta : HTTPMethodMeta , host : HostType | undefined ) {
52+ private createHandler ( methodMeta : HTTPMethodMeta , host : string [ ] | undefined ) {
6153 const argsLength = methodMeta . paramMap . size ;
6254 const hasContext = methodMeta . contextParamIndex !== undefined ;
6355 const contextIndex = methodMeta . contextParamIndex ;
6456 const methodArgsLength = argsLength + ( hasContext ? 1 : 0 ) ;
6557 const self = this ;
6658 return async function ( ctx : Context , next : Next ) {
6759 // if hosts is not empty and host is not matched, not execute
68- if ( host && ! self . hostMatch ( host , ctx . host ) ) {
60+ if ( host && ! host . includes ( ctx . host ) ) {
6961 return await next ( ) ;
7062 }
7163 // HTTP decorator core implement
@@ -170,9 +162,8 @@ export class HTTPMethodRegister {
170162 if ( aclMiddleware ) {
171163 methodMiddlewares . push ( aclMiddleware ) ;
172164 }
173- const host = this . controllerMeta . getMethodHost ( this . methodMeta ) ;
174- const hostList = Array . isArray ( host ) ? host : [ host ] ;
175- hostList . forEach ( h => {
165+ const host = this . controllerMeta . getMethodHost ( this . methodMeta ) || [ undefined ] ;
166+ host . forEach ( h => {
176167 const handler = this . createHandler ( this . methodMeta , h ) ;
177168 Reflect . apply ( routerFunc , this . router ,
178169 [ methodName , methodRealPath , ...methodMiddlewares , handler ] ) ;
0 commit comments