INNER CODE UNIT · TypeScript

resolveShortLink

Hash-Studios/Prism · infra/cloudflare/worker/src/index.ts:231

async function resolveShortLink(pathname: string, request: Request, env: Env): Promise<Response> {
  const code = pathname.replace('/l/', '').trim();
  if (!SHORT_CODE_REGEX.test(code)) {
    return new Response('Invalid code', { status: 400 });
  }

  const record = await readLinkRecord(code, env);
  if (record == null) {
    return new Response('Not found', { status: 404 });
  }

  if (isCrawlerRequest(request)) {
    return html(renderCrawlerPreviewHtml(code, record, env));
  }

  return html(renderHumanLandingHtml(code, record, request, env));
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…