@@ -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 !== ctx . host ) {
6961 return await next ( ) ;
7062 }
7163 // HTTP decorator core implement
@@ -126,9 +118,8 @@ export class HTTPMethodRegister {
126118
127119 // 2. check duplicate with host tegg controller
128120 let hostRouter ;
129- const host = this . controllerMeta . getMethodHost ( this . methodMeta ) ;
130- const hostList = Array . isArray ( host ) ? host : [ host ] ;
131- hostList . forEach ( h => {
121+ const hosts = this . controllerMeta . getMethodHosts ( this . methodMeta ) || [ ] ;
122+ hosts . forEach ( h => {
132123 if ( h ) {
133124 hostRouter = this . checkRouters . get ( h ) ;
134125 if ( ! hostRouter ) {
@@ -170,9 +161,8 @@ export class HTTPMethodRegister {
170161 if ( aclMiddleware ) {
171162 methodMiddlewares . push ( aclMiddleware ) ;
172163 }
173- const host = this . controllerMeta . getMethodHost ( this . methodMeta ) ;
174- const hostList = Array . isArray ( host ) ? host : [ host ] ;
175- hostList . forEach ( h => {
164+ const hosts = this . controllerMeta . getMethodHosts ( this . methodMeta ) || [ undefined ] ;
165+ hosts . forEach ( h => {
176166 const handler = this . createHandler ( this . methodMeta , h ) ;
177167 Reflect . apply ( routerFunc , this . router ,
178168 [ methodName , methodRealPath , ...methodMiddlewares , handler ] ) ;
0 commit comments