From b59673155cc0e9fd300e33115cd02d99093bf43c Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 24 Dec 2019 10:52:10 -0500 Subject: [PATCH] site: in dev mode, proxy /repl/[id].json requests to real server --- site/src/routes/repl/[id]/index.json.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/site/src/routes/repl/[id]/index.json.js b/site/src/routes/repl/[id]/index.json.js index e34329a0e2..de41a4cecd 100644 --- a/site/src/routes/repl/[id]/index.json.js +++ b/site/src/routes/repl/[id]/index.json.js @@ -73,6 +73,18 @@ export async function get(req, res) { }); } + if (process.env.NODE_ENV === 'development') { + // In dev, proxy requests to load particular REPLs to the real server. + // This avoids needing to connect to the real database server. + req.pipe( + require('https').request({ host: 'svelte.dev', path: req.url }) + ).once('response', res_proxy => { + res_proxy.pipe(res); + res.writeHead(res_proxy.statusCode, res_proxy.headers); + }).once('error', () => res.end()); + return; + } + const [row] = await query(` select g.*, u.uid as owner from gists g left join users u on g.user_id = u.id