From 5de3cae599a1ecf99ff44447f52df7c9d3bf7141 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Mon, 5 Oct 2026 02:03:14 -0500 Subject: [PATCH] Redirects: still redirect when site.json can't be read Only the Plausible report is skipped, with a warning, instead of the click failing with a 500. Co-Authored-By: Claude Opus 5.5 --- server/src/routes/redirects.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/routes/redirects.js b/server/src/routes/redirects.js index db97973..5e3e316 100644 --- a/server/src/routes/redirects.js +++ b/server/src/routes/redirects.js @@ -80,8 +80,16 @@ redirects.get("/go/:id", (c, next) => { db.prepare(`UPDATE redirects SET clicks = clicks + 1, last_clicked_at = datetime('now') WHERE id = ?`).run(row.id); - const site = siteFor(db); - tellPlausible(c, site, row.id); + // site.json gives Plausible's domain and an origin to resolve paths + // against. Without it (SITE_CONFIG missing) the visitor still goes + // on; only the Plausible report is skipped. + let site = {}; + try { + site = siteFor(db); + } catch (err) { + console.warn(`redirects: /go/${row.id} without site.json (${err.message}); not reported to Plausible`); + } + if (site.url) tellPlausible(c, site, row.id); for (const [name, value] of Object.entries(NO_STORE)) c.header(name, value); return c.redirect(destination(row, site.url || "http://localhost"), 302); });