request-path.mjs
35 lines 1.1 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 11 days ago
1 /**
2 * Canonical HTTP path for gateway → canister proxy.
3 * Under app.use('/api/v1', handler), Express sets req.path to the suffix (e.g. /notes);
4 * serverless-http / Netlify may leave req.originalUrl inconsistent. Prefer baseUrl + path.
5 */
6
7 /**
8 * @param {import('express').Request} req
9 * @returns {string} pathname only (no query)
10 */
11 export function effectiveRequestPath(req) {
12 const combined = (req.baseUrl || '') + (req.path || '');
13 const noQuery = combined.split('?')[0];
14 if (noQuery.startsWith('/api/v1')) return noQuery;
15 const raw = (req.originalUrl || req.url || '/').split('?')[0];
16 return raw;
17 }
18
19 /**
20 * Path + query for upstream canister (preserve search from originalUrl).
21 * @param {import('express').Request} req
22 */
23 export function upstreamPathAndQuery(req) {
24 const raw = req.originalUrl || req.url || '/';
25 const q = raw.indexOf('?');
26 const search = q >= 0 ? raw.slice(q) : '';
27 return effectiveRequestPath(req) + search;
28 }
29
30 /**
31 * @param {import('express').Request} req
32 */
33 export function pathPartNoQuery(req) {
34 return effectiveRequestPath(req);
35 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 51 days ago