-
|
From what I can see, only How can we access the response headers? |
Beta Was this translation helpful? Give feedback.
Answered by
nktnet1
Aug 22, 2025
Replies: 1 comment
-
|
Workaround for now - use the onResponse hook: onResponse: async (context) => {
const json = await context.response.clone().json();
const headersObj: Record<string, string> = {};
context.response.headers.forEach((v, k) => {
headersObj[k] = v;
});
return new Response(
JSON.stringify({
json,
headers: headersObj,
}),
{
...context.response,
}
);
},Then your If using output, you will need to account for this, e.g. with a helper function: const makeResponseSchema = <T extends v.GenericSchema>(outputSchema: T) => {
return v.object({
json: outputSchema,
headers: v.record(v.string(), v.string()),
});
};Used as follows: "/customers": {
method: "get",
query: v.object({
page: v.optional(v.number()),
from: v.optional(v.string()),
to: v.optional(v.string()),
date_field: v.optional(v.string()),
}),
output: makeResponseSchema(v.array(Customer)),
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nktnet1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workaround for now - use the onResponse hook:
Then your
dataobject will containjsonandheadersas keys.If using output, you will need to account for this, e.g. with a helper function: