From 93ef5d9f4ef7e756f5aeb7ea179bdbfafcdce71c Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Tue, 17 Nov 2026 14:43:33 +1100 Subject: [PATCH] fix(#977): reserve /admin/data-privacy backend route so AdminService OData adapter does not swallow it DataPrivacyService is defined at @(path:'/admin/data-privacy'). AdminService's OData adapter mounts at /admin and intercepts the nested /admin/data-privacy/* path first, returning "Invalid resource path AdminService.data-privacy" (404). This mirrors the existing AnalyticsService (/admin/analytics) late-bound reservation in srv/server.js: declare a stub router, reserve the longer /admin/data-privacy/* prefix in the bootstrap/pre-serve block BEFORE CAP mounts AdminService, then wire the stub to the real DataPrivacyService OData adapter in the cds.on('served') handler (wrapped with the same context + auth middlewares). The approuter route added in #3142 was necessary but not sufficient on its own: the backend still needs this reservation or the request never reaches DataPrivacyService. --- srv/server.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/srv/server.js b/srv/server.js index acfb9a094..53ebc0271 100644 --- a/srv/server.js +++ b/srv/server.js @@ -170,6 +170,15 @@ let embeddingsStatsHandler = (req, res) => res.status(503).json({ error: 'servic // handled correctly rather than falling through to AdminService. let analyticsOdataRouter = (req, res, next) => res.status(503).json({ error: 'service_starting' }); +// Late-bound router for DataPrivacyService at /admin/data-privacy. Same trap as +// /admin/analytics above: AdminService's OData adapter is mounted at /admin and +// would otherwise intercept /admin/data-privacy/* requests, returning +// "Invalid resource path AdminService.data-privacy". By reserving the longer +// /admin/data-privacy/* prefix here (before cds.serve mounts AdminService), +// express routes it to this stub first; in 'served' we wire this variable to the +// real DataPrivacyService OData adapter router (#977). +let dataPrivacyOdataRouter = (req, res, next) => res.status(503).json({ error: 'service_starting' }); + // #805 — Late-bound Express handler for /admin/metrics/live. Same trap as // /admin/analytics/* above: AdminService's OData adapter mounts at /admin // and would otherwise intercept as "Invalid resource path AdminService.metrics.live". @@ -1539,6 +1548,13 @@ cds.on('bootstrap', (app) => { // passes the request through to the AnalyticsService OData layer registered by CDS. app.use('/admin/analytics', (req, res, next) => analyticsOdataRouter(req, res, next)); + // #977 - Reserve /admin/data-privacy/* BEFORE CAP mounts DataPrivacyService. + // Same trap/fix as /admin/analytics above: AdminService's OData adapter mounts + // at /admin and would otherwise swallow /admin/data-privacy/* as + // "Invalid resource path AdminService.data-privacy". Wired to the real adapter + // in 'served'. + app.use('/admin/data-privacy', (req, res, next) => dataPrivacyOdataRouter(req, res, next)); + // Reserve GET /admin/exports/exportLegacyData BEFORE CAP mounts ExportsService at // /admin/exports. Without this, AdminService's OData adapter (mounted at /admin) // would intercept the path first and return "Invalid resource path". Auth + @@ -2177,6 +2193,27 @@ cds.on('served', async () => { cds.log('analytics').warn('AnalyticsService OData adapter not found — /admin/analytics may 404'); } + // #977 - Wire the real DataPrivacyService OData adapter to the stub reserved in + // 'bootstrap'. Same CDS-9/CDS-10 adapter-shape handling and context+auth sandwich + // as the AnalyticsService wire above. + const dataPrivacyDefaultAdapter = cds.services.DataPrivacyService?._adapters?._default; + const dataPrivacyAdapter = typeof dataPrivacyDefaultAdapter === 'function' + ? dataPrivacyDefaultAdapter // CDS 9 shape + : dataPrivacyDefaultAdapter?.router; // CDS 10 shape + if (typeof dataPrivacyAdapter === 'function') { + dataPrivacyOdataRouter = (req, res, next) => { + contextMw(req, res, (err) => { + if (err) return next(err); + authMw(req, res, (err) => { + if (err) return next(err); + dataPrivacyAdapter(req, res, next); + }); + }); + }; + } else { + cds.log('data-privacy').warn('DataPrivacyService OData adapter not found - /admin/data-privacy may 404'); + } + // #805 — Wire the real /admin/metrics/live handler. Same context+auth // sandwich as embeddingsStatsHandler (Admin scope required — the endpoint // exposes in-memory operational data that isn't for public consumption).