-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
386 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ControllerInfoUtil from '../../util/ControllerInfoUtil'; | ||
import { EggProtoImplClass } from '@eggjs/core-decorator'; | ||
import MethodInfoUtil from '../../util/MethodInfoUtil'; | ||
import assert from 'assert'; | ||
|
||
export function Host(host: string) { | ||
function classHost(constructor: EggProtoImplClass) { | ||
ControllerInfoUtil.addControllerHost(host, constructor); | ||
} | ||
|
||
function methodHOst(target: any, propertyKey: PropertyKey) { | ||
assert(typeof propertyKey === 'string', | ||
`[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`); | ||
const controllerClazz = target.constructor as EggProtoImplClass; | ||
const methodName = propertyKey as string; | ||
|
||
MethodInfoUtil.setMethodHost(host, controllerClazz, methodName); | ||
} | ||
|
||
return function(target: any, propertyKey?: PropertyKey) { | ||
if (propertyKey === undefined) { | ||
classHost(target); | ||
} else { | ||
methodHOst(target, propertyKey); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Host } from '../../src/decorator/http/Host'; | ||
|
||
@Host('foo.eggjs.com') | ||
export class HostController { | ||
async hello(): Promise<void> { | ||
return; | ||
} | ||
|
||
@Host('bar.eggjs.com') | ||
async bar(): Promise<void> { | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import assert from 'assert'; | ||
import { HostController } from '../fixtures/HostController'; | ||
import ControllerInfoUtil from '../../src/util/ControllerInfoUtil'; | ||
import MethodInfoUtil from '../../src/util/MethodInfoUtil'; | ||
|
||
describe('test/Host.test.ts', () => { | ||
it('controller Host work', () => { | ||
const controllerHost = ControllerInfoUtil.getControllerHost(HostController); | ||
assert(controllerHost === 'foo.eggjs.com'); | ||
}); | ||
|
||
it('method Host work', () => { | ||
const methodHost = MethodInfoUtil.getMethodHost(HostController, 'bar'); | ||
assert(methodHost === 'bar.eggjs.com'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.