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 <noreply@anthropic.com>
This commit is contained in:
parent
0eea9ba13b
commit
5de3cae599
1 changed files with 10 additions and 2 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue