feat(supabase): owner trial served on the LAN address, sandbox kept on loopback

This commit is contained in:
bchanot committed 2026-11-04 22:36:50 +01:00
1 parent a69eba569b
commit d74c54ed05
6 files changed
+260 -21

No files matched your search

+16 -3
View File
@@ -5,20 +5,33 @@ 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')
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), {
// Loopback even when started by hand: the proxy carries the trial account's session.
// One validated host, never 0.0.0.0: the proxy carries the trial account's session.
server: {
host: '127.0.0.1',
host,
strictPort: true,
allowedHosts: [host],
proxy: Object.fromEntries(
SUPABASE_ROUTES.map((route) => [route, { target }]),
),