web/src/utils/api-config.ts

21 lines · 828 bytes

 1// Base URL and auth for the unified Awesome Privacy API.
 2const strip = (value: string): string => value.replace(/['";]+/g, '').trim();
 3
 4export const apiBase =
 5  strip(import.meta.env.PUBLIC_API_URL || '').replace(/\/+$/, '') ||
 6  'https://api.awesome-privacy.xyz';
 7
 8// Slug a listing name the way the API does, so /v1/services/{slug} resolves.
 9// Note: differs from the web's slugify, which keeps dots (e.g. "Rocket.Chat").
10export const serviceSlug = (name: string): string =>
11  name
12    .toLowerCase()
13    .trim()
14    .replace(/[^a-z0-9]+/g, '-')
15    .replace(/^-|-$/g, '');
16
17// Bearer header for enrichment routes; omitted when no token is set.
18export const enrichHeaders = (): Record<string, string> => {
19  const token = strip(import.meta.env.API_TOKEN || '');
20  return token ? { Authorization: `Bearer ${token}` } : {};
21};