From e3fa547c62b7189465ba9f7f88b80901c3033763 Mon Sep 17 00:00:00 2001 From: Matthew Huebert Date: Sat, 25 May 2024 01:04:18 +0200 Subject: [PATCH] only load /:repo paths in dev env --- package.json | 2 +- server.mjs | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index abe7b04..d7311d0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "scripts": { "start": "node server.mjs", - "dev": "GOOGLE_APPLICATION_CREDENTIALS=key.json BUCKET_NAME=gen-website-private PORT=3000 nodemon server.mjs", + "dev": "GOOGLE_APPLICATION_CREDENTIALS=key.json BUCKET_NAME=gen-website-private ENV=dev PORT=3000 nodemon server.mjs", "dev-rsync": "gcloud storage rsync --recursive --cache-control 'public, max-age=60' ./public gs://gen-website-private/probcomp/test-repo" }, "devDependencies": { diff --git a/server.mjs b/server.mjs index 89b9be7..5e66082 100644 --- a/server.mjs +++ b/server.mjs @@ -75,13 +75,10 @@ const handleFileRequest = async (repo, filePath, res) => { // If there is no extension, serve the main repo index.html filePath = 'index.html'; } - console.log('modified filePath', filePath) // Construct the full path in the bucket const bucketPath = path.join(BUCKET_PREFIX, repo, filePath); - console.log('handleFileRequest', {repo, filePath, bucketPath}) - try { // Serve HTML files directly, otherwise redirect to a signed URL if (filePath.endsWith('.html')) { @@ -101,22 +98,22 @@ const handleFileRequest = async (repo, filePath, res) => { } }; -app.get('/:repo/*', async (req, res) => { - await handleFileRequest(req.params.repo, req.params[0], res); -}); - -app.get('/:repo', async (req, res) => { - await handleFileRequest(req.params.repo, '', res); -}); +if (process.env.ENV == 'dev') { + app.get('/:repo/*', async (req, res) => { + await handleFileRequest(req.params.repo, req.params[0], res); + }); + + app.get('/:repo', async (req, res) => { + await handleFileRequest(req.params.repo, '', res); + }); +} app.get('/*', async (req, res) => { const host = req.hostname; - console.log('host', host) const match = host.match(HOST_REPO_REGEX); if (match) { const repo = match[1]; const filePath = req.params[0]; - console.log('repo', repo, 'filePath', filePath) await handleFileRequest(repo, filePath, res); } else { res.status(404).send('Not Found');