Files
grow-api/src/short-links/short-links.controller.ts
T
2026-07-10 13:26:55 +03:30

23 lines
779 B
TypeScript

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);
}
}