Template
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { FORMATO_CODIGO, registrarClique } from '@/lib/links';
|
|
|
|
// O redirecionamento é feito pelo servidor: GET /<código> → 302 para o link.
|
|
export async function GET(_request: Request, { params }: { params: Promise<{ codigo: string }> }) {
|
|
const { codigo } = await params;
|
|
const link = FORMATO_CODIGO.test(codigo) ? registrarClique(codigo) : null;
|
|
if (!link) {
|
|
return new Response(PAGINA_NAO_ENCONTRADA, {
|
|
status: 404,
|
|
headers: { 'Content-Type': 'text/html; charset=utf-8' },
|
|
});
|
|
}
|
|
return new Response(null, { status: 302, headers: { Location: link.url, 'Cache-Control': 'no-store' } });
|
|
}
|
|
|
|
const PAGINA_NAO_ENCONTRADA = `<!doctype html>
|
|
<html lang="pt-BR">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Link não encontrado</title>
|
|
<style>
|
|
:root { color-scheme: light dark; }
|
|
body {
|
|
margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 16px;
|
|
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
background: #f6f7f9; color: #14161a; line-height: 1.5;
|
|
}
|
|
main { max-width: 420px; text-align: center; }
|
|
h1 { font-size: 24px; margin: 0 0 8px; }
|
|
p { color: #5b6270; margin: 0 0 20px; }
|
|
a { color: #3b5bdb; font-weight: 600; }
|
|
@media (prefers-color-scheme: dark) {
|
|
body { background: #0f1115; color: #eceef2; }
|
|
p { color: #9aa1ad; }
|
|
a { color: #8299ff; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<h1>Link não encontrado</h1>
|
|
<p>Esse link curto não existe ou sumiu quando o app foi publicado de novo.</p>
|
|
<a href="/">Encurtar um link</a>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
`;
|