Events: everything the backend serves is under /api (for 2.3.0)
The site and its API can share one address with one proxy rule (/api to the backend, everything else to the frontend). Status page at /api (/ redirects), /api/health, /api/docs/v2, /api/uploads. Stored upload paths stay /uploads/… and are given out as /api/uploads/…. Old paths still answer (/health, /uploads) or redirect (/docs, /docs/v2), so two-address sites keep working. DEPLOYMENT.md and the agent plan describe the single rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,12 +14,20 @@ export function iso(d: Date | string | null | undefined): string | null {
|
||||
return d == null ? null : new Date(d).toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a stored upload path is served: "/uploads/…" (as stored) → "/api/uploads/…" (2.3.0), so it
|
||||
* reaches the backend when the site and its API share one address. Anything else is unchanged.
|
||||
*/
|
||||
export function uploadPath(raw: string): string {
|
||||
return /^\/uploads\//.test(raw) ? `/api${raw}` : raw;
|
||||
}
|
||||
|
||||
/** A stored picture path ("/uploads/…") as an absolute URL on the host the request came to. */
|
||||
export function absoluteUrl(req: Request, url: string | null | undefined): string | null {
|
||||
const raw = String(url || '').trim();
|
||||
if (!raw) return null;
|
||||
if (/^https?:\/\//.test(raw)) return raw;
|
||||
return `${req.protocol}://${req.get('host')}${raw.startsWith('/') ? '' : '/'}${raw}`;
|
||||
return `${req.protocol}://${req.get('host')}${uploadPath(raw.startsWith('/') ? raw : `/${raw}`)}`;
|
||||
}
|
||||
|
||||
export const campusRef = z.object({ id, name: z.string(), slug: z.string() });
|
||||
|
||||
Reference in New Issue
Block a user