import { Controller, Get, Param, Res } from '@nestjs/common'; import { ApiExcludeController } from '@nestjs/swagger'; import type { Response } from 'express'; import { Public } from '../auth/decorators/public.decorator'; import { ShortLinksService } from './short-links.service'; /** * Registered outside the global `api` prefix (see main.ts) so links stay short, * e.g. `https://api.example.com/s/aB3xQ9k`. */ @ApiExcludeController() @Controller('s') export class ShortLinksController { constructor(private readonly shortLinksService: ShortLinksService) {} @Public() @Get(':code') async redirect(@Param('code') code: string, @Res() res: Response) { const targetUrl = await this.shortLinksService.resolveAndTrack(code); return res.redirect(targetUrl); } }