mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-26 01:24:59 +02:00
- Add 11 missing GET routes to RPC_CACHE_TIER map (8 slow, 3 medium) - Add response-headers side-channel (WeakMap) so handlers can signal X-No-Cache without codegen changes; wire into military-flights and positive-geo-events handlers on upstream failure - Add env-controlled per-endpoint tier override (CACHE_TIER_OVERRIDE_*) for incident response rollback - Add VITE_WS_API_URL hostname allowlist (*.worldmonitor.app + localhost) - Fix fetch.bind(globalThis) in positive-events-geo.ts (deferred lambda) - Add CI test asserting every generated GET route has an explicit cache tier entry (prevents silent default-tier drift)
29 lines
863 B
TypeScript
29 lines
863 B
TypeScript
/**
|
|
* Side-channel for handlers to attach response headers without modifying codegen.
|
|
*
|
|
* Handlers set headers via setResponseHeader(ctx.request, key, value).
|
|
* The gateway reads and applies them after the handler returns.
|
|
* WeakMap ensures automatic cleanup when the Request is GC'd.
|
|
*/
|
|
|
|
const channel = new WeakMap<Request, Record<string, string>>();
|
|
|
|
export function setResponseHeader(req: Request, key: string, value: string): void {
|
|
let headers = channel.get(req);
|
|
if (!headers) {
|
|
headers = {};
|
|
channel.set(req, headers);
|
|
}
|
|
headers[key] = value;
|
|
}
|
|
|
|
export function markNoCacheResponse(req: Request): void {
|
|
setResponseHeader(req, 'X-No-Cache', '1');
|
|
}
|
|
|
|
export function drainResponseHeaders(req: Request): Record<string, string> | undefined {
|
|
const headers = channel.get(req);
|
|
if (headers) channel.delete(req);
|
|
return headers;
|
|
}
|