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/workers-types@4.20240502.0/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.