feat: include query params in server-to-app request mapping

This commit is contained in:
Codex
2026-02-18 12:54:37 +00:00
parent 8be203fb91
commit 2fa4f62632
2 changed files with 5 additions and 1 deletions

View File

@@ -30,9 +30,11 @@ function normalizeHeaders(rawHeaders) {
function mapToAppRequest({ req, rawBody }) { function mapToAppRequest({ req, rawBody }) {
const url = new URL(req.url, "http://localhost"); const url = new URL(req.url, "http://localhost");
const query = Object.fromEntries(url.searchParams.entries());
return { return {
method: req.method || "GET", method: req.method || "GET",
path: url.pathname, path: url.pathname,
query,
headers: normalizeHeaders(req.headers), headers: normalizeHeaders(req.headers),
rawBody, rawBody,
}; };

View File

@@ -18,7 +18,7 @@ test("mapToAppRequest extracts method/path/headers/body correctly", () => {
const request = mapToAppRequest({ const request = mapToAppRequest({
req: { req: {
method: "POST", method: "POST",
url: "/api/webhooks/x?debug=1", url: "/api/webhooks/x?debug=1&returnTo=%2Faudio%2F1",
headers: { "X-Signature": "sha256=abc" }, headers: { "X-Signature": "sha256=abc" },
}, },
rawBody: "{\"ok\":true}", rawBody: "{\"ok\":true}",
@@ -26,6 +26,8 @@ test("mapToAppRequest extracts method/path/headers/body correctly", () => {
assert.equal(request.method, "POST"); assert.equal(request.method, "POST");
assert.equal(request.path, "/api/webhooks/x"); assert.equal(request.path, "/api/webhooks/x");
assert.equal(request.query.debug, "1");
assert.equal(request.query.returnTo, "/audio/1");
assert.equal(request.headers["x-signature"], "sha256=abc"); assert.equal(request.headers["x-signature"], "sha256=abc");
assert.equal(request.rawBody, "{\"ok\":true}"); assert.equal(request.rawBody, "{\"ok\":true}");
}); });