IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    新手入门Nest.js(九)- 控制器子域名路由

    Durban发表于 2020-10-03 23:38:27
    love 0

    子域路由

    @Controller装饰器提供了一个host选项可用,主要用来判断这个控制器在被访问的时候,限制具体的域名来访问

    代码如下

    @Controller('cats')
    @Controller({ host: 'api.gowhich.com' })
    export class CatsController {
      @Get()
      findAll(@Req() request: Request): string {
        return 'This action will returns all cats';
      }
    }

    再举个例子

    @Controller('cats')
    @Controller({ host: 'api.gowhich.com' })
    export class CatsController {
      @Get()
      getInfo(@HostParam('account') account) {
        return account;
      }
    }

     



沪ICP备19023445号-2号
友情链接