feat: include query params in server-to-app request mapping
This commit is contained in:
@@ -30,9 +30,11 @@ function normalizeHeaders(rawHeaders) {
|
||||
|
||||
function mapToAppRequest({ req, rawBody }) {
|
||||
const url = new URL(req.url, "http://localhost");
|
||||
const query = Object.fromEntries(url.searchParams.entries());
|
||||
return {
|
||||
method: req.method || "GET",
|
||||
path: url.pathname,
|
||||
query,
|
||||
headers: normalizeHeaders(req.headers),
|
||||
rawBody,
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ test("mapToAppRequest extracts method/path/headers/body correctly", () => {
|
||||
const request = mapToAppRequest({
|
||||
req: {
|
||||
method: "POST",
|
||||
url: "/api/webhooks/x?debug=1",
|
||||
url: "/api/webhooks/x?debug=1&returnTo=%2Faudio%2F1",
|
||||
headers: { "X-Signature": "sha256=abc" },
|
||||
},
|
||||
rawBody: "{\"ok\":true}",
|
||||
@@ -26,6 +26,8 @@ test("mapToAppRequest extracts method/path/headers/body correctly", () => {
|
||||
|
||||
assert.equal(request.method, "POST");
|
||||
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.rawBody, "{\"ok\":true}");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user