From 1d9b87500d3bdb2e208e57e1bca2476db2311cd7 Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 1 Sep 2026 09:00:17 +0200 Subject: [PATCH] Fix "Add to calendar" 400 when FRONTEND_URL lacks a scheme The ics library's url validator requires a scheme (https://...), but production's FRONTEND_URL/APP_BASE_URL was configured without one, so createEvent() rejected every request before generating a .ics file. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01PAwumFeBwx6XSsQXp8Nfqt --- CHANGELOG.md | 4 ++++ backend/src/controllers/eventController.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cd13d..0da3ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project follows [Semantic Versioning](https://semver.org/). ## [Unreleased] +### Fixed + +- "Add to calendar" (`GET /api/events/:id/ics`) always failed with a 400 in production: the `ics` library's `url` field requires a scheme (`https://...`), but `FRONTEND_URL`/`APP_BASE_URL` was configured without one, so `createEvent()` rejected it before generating any output. A missing scheme is now assumed to be `https://` instead of failing. + ## [1.10.3] - 2026-08-28 ### Fixed diff --git a/backend/src/controllers/eventController.js b/backend/src/controllers/eventController.js index ebce80e..964c32b 100644 --- a/backend/src/controllers/eventController.js +++ b/backend/src/controllers/eventController.js @@ -493,7 +493,12 @@ const getEventIcs = async (req, res) => { } const { buildEventIcs } = require('../utils/icsUtils'); - const frontendUrl = (process.env.FRONTEND_URL || process.env.APP_BASE_URL || 'http://localhost:3001').replace(/\/$/, ''); + let frontendUrl = (process.env.FRONTEND_URL || process.env.APP_BASE_URL || 'http://localhost:3001').replace(/\/$/, ''); + // The ics library's url validator requires a scheme; guard against FRONTEND_URL/APP_BASE_URL + // being configured without one (e.g. "example.com" instead of "https://example.com"). + if (!/^[a-z0-9+.-]+:\/\//i.test(frontendUrl)) { + frontendUrl = `https://${frontendUrl}`; + } const ics = buildEventIcs(event, `${frontendUrl}/events/${event.id}`); res.setHeader('Content-Type', 'text/calendar; charset=utf-8');