Greg Brimble | Cloudflare Pages
11/29/2021, 1:02 PMts
export const onRequest = (context) => {
return new Response(context.env.SOME_API_KEY)
}
Should do it!Kev
11/29/2021, 1:02 PMKev
11/29/2021, 1:02 PMGreg Brimble | Cloudflare Pages
11/29/2021, 1:02 PMcontext
has a bunch of things in it, including env
which holds all your bindings.Kev
11/29/2021, 1:03 PMoliverjam
11/29/2021, 1:54 PMset-cookie
being a "Forbidden response header name" 👻 (https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_response_header_name).
I had to do something like this to create an entirely new response with the right headers:
js
let originalResponse = await next();
let headers = new Headers(originalResponse.headers);
headers.append("set-cookie", "test=123");
let response = new Response(originalResponse.body, { status: originalResponse.status, headers });
Deleted User
11/29/2021, 4:42 PMGreg Brimble | Cloudflare Pages
11/29/2021, 4:43 PMonRequest
, onRequestGet
etc.) the file is ignored.Deleted User
11/29/2021, 4:43 PMGreg Brimble | Cloudflare Pages
11/29/2021, 4:43 PMtsconfig.json
), but we're working on it, and those will be excluded too.ReaverCelty
11/29/2021, 4:46 PMwasm_modules
or get access to a resources tab?Adriaan
11/29/2021, 5:38 PMWrangler2 pages dev
. It's interesting that when the functions are deployed to the pages platform, you can just append the headers directly (without created a new Header class).oliverjam
11/29/2021, 5:43 PMnode-fetch
to implement things like Response
and Headers
). I did just look through the source code and I couldn't see anything in there specifically about set-cookie
or forbidden response header names though 🤷oliverjam
11/29/2021, 5:53 PMjs
// functions/index.js
export function onRequestGet() {
let res = new Response("hello");
res.headers.append("set-cookie", "test=123");
return res;
}
but this works fine:
js
// functions/index.js
export function onRequestGet() {
let res = new Response("hello", {
headers: { "set-cookie": "test=123" }
});
return res;
}
oliverjam
11/29/2021, 6:15 PMJames
11/29/2021, 6:26 PMminiflare
specifically and not wrangler2
- I'm not sure, but I imagine emulating as closely as possible with local dev and prod is a goal.Walshy | Pages
11/29/2021, 6:27 PMWalshy | Pages
11/29/2021, 6:28 PMoliverjam
11/29/2021, 6:37 PMoliverjam
11/29/2021, 6:37 PMfetch
spec right now 😅James
11/29/2021, 6:54 PMv2
branch in miniflare with the up to date version used in wrangler2 if you wanted to take a look 🙂James
11/29/2021, 6:54 PMErwin
11/30/2021, 12:45 AMctc.waitUntil
bug should be fixed and released.. Could you please give it another go and let us know if it fixes both your issues?Greg Brimble | Cloudflare Pages
11/30/2021, 12:45 AMwrangler@alpha
, but not quite in production yet.Erwin
11/30/2021, 12:46 AMplinko
thing, not Wrangler right?chrisjmccreadie
11/30/2021, 7:29 AMchrisjmccreadie
11/30/2021, 7:29 AMrkusa
11/30/2021, 8:00 AMgeelen
11/30/2021, 9:41 AM