Files
caldav/api/sidecar-server.ts
pastilhasandClaude Opus 5 bfb12c2dde drop the jsonBody workaround — the platform parses these bodies now
this plugin read ctx.req.json() directly because registerProxiedPrefix claimed
the whole of /api/caldav, so bodyParser skipped the plugin's OWN routes and every
field read as missing.

the platform's proxy takes a proxiedSubPath now, so this claims only
/api/caldav/_officer — what the sidecar actually answers — and /passwords and
/provision/ios get their bodies the ordinary way.

verified end to end: POST /api/caldav/passwords with a label came back with the
label, and _officer/collections still reaches the sidecar.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Officer-Session: 656f5c85-e49a-4f1f-b9f3-042a04b4d043
2026-08-27 08:48:53 +00:00

23 lines
1.4 KiB
TypeScript

import { createSidecarProxy } from '@@/sidecar/create-proxy';
// The officer-caldav sidecar has TWO consumers in the platform and they need different things, so the
// port capture lives here and both import it.
//
// • `caldavRouter` — the ordinary JSON door for Officer's own UI. Behind userMiddleware, forwarded by
// the shared factory with `X-Officer-User`, exactly like every other sidecar.
// • `davSyncRouter` — the DAV door for phones. Cannot use the factory: it forwards only three headers
// (`create-proxy.ts:88`) and DAV dies without `Depth`, and it derives the user from a platform JWT
// that a DAV client has no way to hold.
//
// Hence one registration, two forwarders. The factory's own comment says it must never grow per-app
// logic, so the DAV-specific half is a separate file rather than a branch inside it.
// `proxiedSubPath`: this sidecar answers `_officer/*` and nothing else, so the proxy claims only that.
//
// Claiming the whole prefix is what stopped this plugin's OWN routes from seeing a request body —
// `registerProxiedPrefix` tells bodyParser to leave the prefix alone, which is right for forwarded
// traffic and wrong for `/passwords` and `/provision/ios`, which are served here.
const proxy = createSidecarProxy({ name: 'caldav', prefix: '/api/caldav', proxiedSubPath: '/_officer' });
export const caldavRouter = proxy.router;
export const getCaldavUrl = proxy.getHttpUrl;