Files
faunosteo/apps/app/vite/trial.config.ts
T

41 lines
1.4 KiB
TypeScript

import { defineConfig, mergeConfig } from 'vite'
import base from '../vite.config'
/**
* Dev server of `pnpm db:sandbox trial` (docs/development/V1-2-6_OWNER_TRIAL.md).
* The browser talks to this origin only: the three Supabase routes are
* forwarded to the trial gateway on loopback, so no CORS rule is involved.
* The server binds the one host that scripts/db-sandbox.sh validated (loopback or a private
* address of this machine) and refuses any other Host header.
*/
const target = process.env.FAUNOSTEO_TRIAL_GATEWAY
const url = target ? new URL(target) : null
if (!url || url.protocol !== 'http:' || url.hostname !== '127.0.0.1')
throw new Error(
'FAUNOSTEO_TRIAL_GATEWAY must be an http://127.0.0.1:<port> URL',
)
const host = process.env.FAUNOSTEO_TRIAL_HOST ?? ''
const PRIVATE_IPV4 =
/^(127\.0\.0\.1|10(\.\d{1,3}){3}|172\.(1[6-9]|2\d|3[01])(\.\d{1,3}){2}|192\.168(\.\d{1,3}){2})$/
if (!PRIVATE_IPV4.test(host))
throw new Error(
'FAUNOSTEO_TRIAL_HOST must be 127.0.0.1 or a private IPv4 address',
)
const SUPABASE_ROUTES = ['/auth/v1', '/rest/v1', '/storage/v1']
export default defineConfig((env) =>
mergeConfig(base(env), {
// One validated host, never 0.0.0.0: the proxy carries the trial account's session.
server: {
host,
strictPort: true,
allowedHosts: [host],
proxy: Object.fromEntries(
SUPABASE_ROUTES.map((route) => [route, { target }]),
),
},
}),
)