diff --git a/sites/svelte.dev/README.md b/sites/svelte.dev/README.md index 3eed3b79..3634ed4f 100644 --- a/sites/svelte.dev/README.md +++ b/sites/svelte.dev/README.md @@ -1,6 +1,10 @@ ## Running locally -Setup a database on [Supabase](https://supabase.com) with the instructions [here](../../db) and set the corresponding environment variables. +A local database is only required in dev mode if you want to test reading and writing saved REPLs on it. Without a local database in dev mode, the REPL will be able to load saved REPLs from the production database, but not save them. + +Note also that in dev mode, the REPL will currently only work in Chrome, [as noted in the Vite documentation](https://vitejs.dev/guide/features.html#web-workers), pending support in Firefox for `import` statements in web workers. + +If you do want to use a database, set it up on [Supabase](https://supabase.com) with the instructions [here](../../db) and set the corresponding environment variables. Run the site sub-project: diff --git a/sites/svelte.dev/src/lib/db/client.js b/sites/svelte.dev/src/lib/db/client.js index d80110ad..6b45b41e 100644 --- a/sites/svelte.dev/src/lib/db/client.js +++ b/sites/svelte.dev/src/lib/db/client.js @@ -1,6 +1,8 @@ +import { dev } from '$app/env'; import { createClient } from '@supabase/supabase-js'; -const SUPABASE_URL = process.env['SUPABASE_URL']; -const SUPABASE_KEY = process.env['SUPABASE_KEY']; +const SUPABASE_URL = process.env.SUPABASE_URL; +const SUPABASE_KEY = process.env.SUPABASE_KEY; -export const client = createClient(SUPABASE_URL, SUPABASE_KEY, { fetch }); +export const client = + (!dev || (SUPABASE_URL && SUPABASE_KEY)) && createClient(SUPABASE_URL, SUPABASE_KEY, { fetch }); diff --git a/sites/svelte.dev/src/routes/repl/[id]/index.json.js b/sites/svelte.dev/src/routes/repl/[id]/index.json.js index 8483d9a0..fcb262a6 100644 --- a/sites/svelte.dev/src/routes/repl/[id]/index.json.js +++ b/sites/svelte.dev/src/routes/repl/[id]/index.json.js @@ -1,3 +1,5 @@ +import { dev } from '$app/env'; +import { client } from '$lib/db/client'; import * as gist from '$lib/db/gist'; import { API_BASE } from '$lib/env'; @@ -58,6 +60,12 @@ export async function get({ params }) { }; } + if (dev && !client) { + // in dev with no local Supabase configured, proxy to production + // this lets us at least load saved REPLs + return fetch(`https://svelte.dev/repl/${params.id}.json`); + } + const app = await gist.read(params.id); if (!app) {