fix(supabase): LAN trial without CORS, hot-reload socket or editor launch

This commit is contained in:
bchanot committed 2026-11-04 23:30:52 +01:00
1 parent 671a1bde40
commit 8531dd30d8
2 files changed
+13 -6

No files matched your search

+9 -4
View File
@@ -28,16 +28,17 @@ const SUPABASE_ROUTES = ['/auth/v1', '/rest/v1', '/storage/v1']
const REPO = fileURLToPath(new URL('../../../', import.meta.url))
/**
* `allowedHosts` still lets every IP literal and localhost through (Vite 7):
* any Host other than the trial host gets a 403.
* `allowedHosts` still lets every IP literal and localhost through (Vite 7): any HTTP request
* whose Host is not the trial host gets a 403, and the editor-launch route is closed to the LAN.
*/
const trialHostOnly: Plugin = {
name: 'faunosteo-trial-host-only',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const name = (req.headers.host ?? '').replace(/:\d+$/, '')
if (name === host) return next()
res.statusCode = 403
const launch = (req.url ?? '').toLowerCase().includes('/__open-in-editor')
if (name === host && !launch) return next()
res.statusCode = name === host ? 404 : 403
res.end()
})
},
@@ -51,6 +52,10 @@ export default defineConfig((env) =>
host,
strictPort: true,
allowedHosts: [host],
// Same origin through the proxy: no CORS answer, and no hot-reload socket (its upgrade
// skips the middlewares above) on a manual trial.
cors: false,
ws: false,
// The LAN sees the app's own sources only: never the repository's notes, seed or builds.
fs: { allow: ['apps/app', 'packages', 'node_modules'].map((dir) => REPO + dir) },
proxy: Object.fromEntries(