env.ASSETS.fetch doesn't return additional headers
I have a Pages project with a worker (advanced config) that attempts to add a cookie via adding headers to the env.ASSETS.fetch call
the headers are not returned.
to sanity check if i return the following ther are:
to workaround i could either redirect (with the cookies), but what i'm attempting above seems reasonable so i wonder if there's an API bug?
21 Replies
Not quite. Instead of returning a
Response
with a set-cookie
header, your code is sending the request to the ASSETS
binding with a set-cookie
header. You want hi thanks for the quick response.
for that i got:
i shouldn't need to await the body?
related (TS issue) @cloudflare/workers-types doesn't export a Response type (it does for Request, etc.) so the native Node Response seems differnet from the one that the worker implements/provides?
It should be? https://workers-types.pages.dev/
oh. could it be that that's been updated recently? the code isn't open source right? i'm pretty user the export was missing a couple of days ago. (but you're right it's there now).
well, it still doesn't compile
It is. I don't remember where the generator code lives, but the package is here: https://github.com/cloudflare/workerd/tree/main/npm/workers-types
GitHub
workerd/npm/workers-types at main · cloudflare/workerd
The JavaScript / Wasm runtime that powers Cloudflare Workers - cloudflare/workerd
Not sure why it is throwing that. Here's that exact file, and I do see
export declare class Response extends Body {
...
https://cdn.jsdelivr.net/npm/@cloudflare/[email protected]/index.tsright. i see that.
⛅️ wrangler 3.53.0 (update available 3.53.1)
does my tsconfig look okay?
it's strange -- my IDE was reporting Response as missing last week, so i commented out the import and used casts.
now the IDE isn't complaing but the build fails, so it feels like something has updated recentely and is out of sync
If you have the
types
in your tsconfig.json
, then you shouldn't need to import any types at allI've imported the CF Request since i wanted to access the typed cf property
request.cf
? That should be typed automatically toosrc/auth.ts:75:31 - error TS2339: Property 'cf' does not exist on type 'Request'.
Is that a Node/DOM
Request
too?that's the main request handler.
(request: Request, env: Env, c)
Yeah, I think it is using a DOM/Node Request, rather than the CF Request
Per your
tsconfig
it should use the CF request, but iirc some depencies can override your config(for some dumb reason)ok well my workaround is
(request as any).cf
; it's a pity since the CF TS system is really nice.
i'll investigate what might be happening with our tsconfig that might be interfering with this.
thanks very much for your help.Just as a sanity check, if you start a new project with the following
tsconfig.json
: , and then a src/index.ts
with the following, do you see any type errors? it'll take me a moment to set that up but i'll try that out -- do you mind if i ping you back on this.
Sounds good
hi @HardlyWorkin' i figured out the issue was that I had
"lib": ["ESNext", "DOM"]
in my tsconfig and the "DOM" lib overrides the CF types (for DOM Request/Response). if i now remove that then fetch
is undefined so i'm still tracking that down.Oh yeah, that’ll do it
the way around is to have a separate tsconfi.spec.json for the tests (e.g., for clients which require fetch). thanks again for the help.