@nestjs/common#Redirect TypeScript Examples

The following examples show how to use @nestjs/common#Redirect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: system.controller.ts    From life-helper-backend with MIT License 6 votes vote down vote up
/**
   * 网站标志
   *
   *
   * ### 功能说明
   *
   * ```markdown
   * 1. 在使用浏览器直接输入 URL 访问,会自动请求获取 `/favicon.ico`,然后在标签页上显示。
   * 2. 当前项目实际上用不到 `favicon.ico`,因为这个项目对外仅提供 API 接口。
   * 3. 为避免调试的时候,控制台报错找不到 `favicon.ico`,所以加了这个。
   * ```
   */
  @Get('favicon.ico')
  @Redirect('https://www.lifehelper.com.cn/favicon.ico')
  favicon(): void {
    // 2021-08-26,这条注释仅用于占位,避免报 `no-empty-function` 错误
  }
Example #2
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@ApiCookieAuth()
  @ApiBody({ type: SignInDto })
  @ApiMovedPermanentlyResponse({ description: 'Returns 301 if login is ok' })
  @ApiInternalServerErrorResponse({
    description: 'Returns 500 if smth has been failed',
  })
  @HttpCode(HttpStatus.MOVED_PERMANENTLY)
  @UseGuards(LocalAuthGuard)
  @Post('/login')
  @Redirect('/v1/home')
  public login(): void {}
Example #3
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@ApiMovedPermanentlyResponse({ description: 'Redirects to home' })
  @ApiInternalServerErrorResponse({ description: 'Returns the 500 error' })
  @Post('/register')
  @Redirect('/v1/auth/login')
  public async create(@Body() params: SignUpDto): Promise<void> {
    const { email, _id } = await this.usersService.create(params) as UserDocument;
    const token = await this.authService.createVerifyToken(_id);

    await this.mailerService.sendMail({
      to: email,
      from: this.configService.get<string>('MAILER_FROM_EMAIL'),
      subject: 'Email Verification',
      template: `${process.cwd()}/public/views/mailer/templates/verify-password`,
      context: {
        token,
        email,
        host: this.configService.get<number>('SERVER_HOST'),
      },
    });
  }
Example #4
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@ApiCookieAuth()
  @ApiBody({ type: SignInDto })
  @ApiMovedPermanentlyResponse({ description: 'Returns 301 if login is ok' })
  @ApiInternalServerErrorResponse({
    description: 'Returns 500 if smth has been failed',
  })
  @HttpCode(HttpStatus.MOVED_PERMANENTLY)
  @UseGuards(LocalAuthGuard)
  @Post('/login')
  @Redirect('/v1/home')
  public login(): void { }
Example #5
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@Get('verify/:token')
  @Redirect('/v1/home')
  async verifyUser(
    @Req() req: ExpressRequest,
    @Param('token') token: string,
  ): Promise<any> {
    const id: Types.ObjectId = await this.authService.verifyEmailVerToken(token);
    if (!id) {
      return {
        message: req.flash('The user does not exist'),
      };
    }
    const foundUser = await this.usersService.verifyUser(id);
    if (!foundUser) {
      return {
        message: req.flash('The user does not exist'),
      };
    }
  }
Example #6
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@ApiMovedPermanentlyResponse({ description: 'Redirects to home' })
  @ApiInternalServerErrorResponse({ description: 'Returns the 500 error' })
  @Post('/register')
  @Redirect('/v1/auth/login')
  public async create(@Body() params: SignUpDto): Promise<void> {
    const { email, id } = await this.usersService.create(params);
    const token = await this.authService.createVerifyToken(id);
    await this.mailerService.sendMail({
      to: email,
      from: this.configService.get<string>('MAILER_FROM_EMAIL'),
      subject: 'Email Verification',
      template: `${process.cwd()}/public/views/mailer/templates/verify-password`,
      context: {
        token,
        email,
        host: this.configService.get<number>('SERVER_HOST'),
      },
    });
  }
Example #7
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@ApiCookieAuth()
  @ApiBody({ type: SignInDto })
  @ApiMovedPermanentlyResponse({ description: 'Returns 301 if login is ok' })
  @ApiInternalServerErrorResponse({
    description: 'Returns 500 if smth has been failed',
  })
  @HttpCode(HttpStatus.MOVED_PERMANENTLY)
  @UseGuards(LocalAuthGuard)
  @Post('/login')
  @Redirect('/home')
  public login(): void {}
Example #8
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@Get('verify/:token')
  @Redirect('/v1/home')
  async verifyUser(
    @Req() req: ExpressRequest,
    @Param('token') token: string,
  ): Promise<any> {
    const id = await this.authService.verifyEmailVerToken(token);
    if (!id) {
      return {
        message: req.flash('The user does not exist'),
      };
    }
    const foundUser = await this.usersService.verifyUser(id);
    if (!foundUser) {
      return {
        message: req.flash('The user does not exist'),
      };
    }
  }
Example #9
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 5 votes vote down vote up
@ApiMovedPermanentlyResponse({ description: '301. If logout is success' })
  @ApiInternalServerErrorResponse({ description: 'Internal error' })
  @Get('/logout')
  @Redirect('/v1/auth/login')
  public logout(@Request() req: ExpressRequest): void {
    req.logout();
  }
Example #10
Source File: legacy-route.controller.ts    From erda-ui with GNU Affero General Public License v3.0 5 votes vote down vote up
@Get('edge/*')
  @Redirect('', 301)
  redirectEdge(@Req() req: Request) {
    return { url: req.path.replace('edge', 'ecp') };
  }
Example #11
Source File: legacy-route.controller.ts    From erda-ui with GNU Affero General Public License v3.0 5 votes vote down vote up
@Get('dataCenter/*')
  @Redirect('', 301)
  redirectDataCenter(@Req() req: Request) {
    return { url: req.path.replace('dataCenter', 'cmp') };
  }
Example #12
Source File: legacy-route.controller.ts    From erda-ui with GNU Affero General Public License v3.0 5 votes vote down vote up
@Get('microService/*')
  @Redirect('', 301)
  redirectMicroService(@Req() req: Request) {
    return { url: req.path.replace('microService', 'msp') };
  }
Example #13
Source File: legacy-route.controller.ts    From erda-ui with GNU Affero General Public License v3.0 5 votes vote down vote up
@Get('workBench/*')
  @Redirect('', 301)
  redirectWorkBench(@Req() req: Request) {
    return { url: req.path.replace('workBench', 'dop') };
  }
Example #14
Source File: app.controller.ts    From aqualink-app with MIT License 5 votes vote down vote up
@ApiExcludeEndpoint()
  @Get()
  @Redirect('/api/docs')
  getDocs() {
    this.logger.log('Redirecting to /api/docs');
  }
Example #15
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 5 votes vote down vote up
@ApiMovedPermanentlyResponse({ description: 'Redirects to home' })
  @ApiInternalServerErrorResponse({ description: 'Returns the 500 error' })
  @Post('/register')
  @Redirect('/v1/auth/login')
  public async create(@Body() params: SignUpDto): Promise<void> {
    await this.usersService.create(params);
  }
Example #16
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 5 votes vote down vote up
@ApiMovedPermanentlyResponse({ description: '301. If logout is success' })
  @ApiInternalServerErrorResponse({ description: 'Internal error' })
  @Get('/logout')
  @Redirect('/v1/auth/login')
  public logout(@Request() req: ExpressRequest): void {
    req.logout();
  }
Example #17
Source File: auth.controller.ts    From nest-js-boilerplate with MIT License 5 votes vote down vote up
@ApiMovedPermanentlyResponse({ description: '301. If logout is success' })
  @ApiInternalServerErrorResponse({ description: 'Internal error' })
  @Get('/logout')
  @Redirect('/v1/auth/login')
  public logout(@Request() req: ExpressRequest): void {
    req.logout();
  }