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.
| Variable | Description | Example |
|---|---|---|
SUPABASE_URL | Target Supabase project URL (determines prod vs dev routing) | https://xyz.supabase.co |
ADMIN_API_KEY | Admin key for the Edge Function x-admin-key header | your-secret-key |
BASIC_AUTH_USER | Username for the portal login form | admin |
BASIC_AUTH_PASSWORD | Password for the portal login form | your-password |
See .env.example for the full list with descriptions.
Deployments
Two separate Vercel projects, same codebase, different env vars:
| Domain | Vercel Project | SUPABASE_URL |
|---|---|---|
api.scalex.com.ua | api-portal-prod | https://aqbchetcfyqtyrdjznvz.supabase.co |
dev.api.scalex.com.ua | api-portal-dev | https://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
- Create a new Vercel project linked to this repo
- Set
SUPABASE_URL(and other env vars) for the new project - Add a custom domain
- 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:3000Full local dev (with functions and routing):
vercel dev # runs build + auto-detects api/*.js functionsInspect the generated build output (mirrors what Vercel runs):
SUPABASE_URL=https://your-project.supabase.co node scripts/build.mjs
# check .vercel/output/config.json