request-path.mjs
35 lines 1.1 KB
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor ⚠ breaking 12 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 1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882 fix(test): align Band B landing assertion with desktop MCP … Human 12 days ago