api-portal

Swagger UI portal for the Scalex API. Hosted on Vercel, deployed once per environment.

Architecture

Browser
  │
  ├── GET /                    → static index.html (Swagger UI)
  ├── GET /api/auth            → serverless fn: validates Basic Auth credentials
  ├── GET /api/swagger-spec    → serverless fn: fetches OpenAPI spec from Supabase,
  │                              injects x-admin-key server-side (key never reaches browser)
  │
  └── /functions/v1/*          → static CDN rewrite → Supabase Functions
      /rest/v1/*               → static CDN rewrite → Supabase REST API

Proxy rewrites are handled at Vercel’s CDN edge — no serverless function is invoked. This means proxy traffic is free and unlimited regardless of request volume.

The target Supabase URL is embedded at build time (not hardcoded in source) using the Vercel Build Output API v3. The build script scripts/build.mjs reads SUPABASE_URL from the environment and writes it into .vercel/output/config.json as a static route destination.

Environment Variables

Set these in Vercel → Project → Settings → Environment Variables for each deployment.

VariableDescriptionExample
SUPABASE_URLTarget Supabase project URL (determines prod vs dev routing)https://xyz.supabase.co
ADMIN_API_KEYAdmin key for the Edge Function x-admin-key headeryour-secret-key
BASIC_AUTH_USERUsername for the portal login formadmin
BASIC_AUTH_PASSWORDPassword for the portal login formyour-password

See .env.example for the full list with descriptions.

Deployments

Two separate Vercel projects, same codebase, different env vars:

DomainVercel ProjectSUPABASE_URL
api.scalex.com.uaapi-portal-prodhttps://aqbchetcfyqtyrdjznvz.supabase.co
dev.api.scalex.com.uaapi-portal-devhttps://jfmdrdleyyclgqjjowxt.supabase.co

Each deploy triggers node scripts/build.mjs, which reads the project’s SUPABASE_URL and bakes it into the static routing config for that deployment.

Adding a new environment

  1. Create a new Vercel project linked to this repo
  2. Set SUPABASE_URL (and other env vars) for the new project
  3. Add a custom domain
  4. Deploy — the build script auto-configures routing to the correct Supabase project

Local Development

Static preview only (no serverless functions):

pnpm dev        # serves index.html on http://localhost:3000

Full local dev (with functions and routing):

vercel dev      # runs build + auto-detects api/*.js functions

Inspect the generated build output (mirrors what Vercel runs):

SUPABASE_URL=https://your-project.supabase.co node scripts/build.mjs
# check .vercel/output/config.json