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); });