Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@astrojs/vercel endpoint breaks when sending set-cookie #5461

Closed
1 task done
WesSouza opened this issue Nov 23, 2022 · 2 comments
Closed
1 task done

@astrojs/vercel endpoint breaks when sending set-cookie #5461

WesSouza opened this issue Nov 23, 2022 · 2 comments
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@WesSouza
Copy link
Contributor

WesSouza commented Nov 23, 2022

What version of astro are you using?

1.6.10

Are you using an SSR adapter? If so, which one?

Vercel

What is the Node.js version?

18

What package manager are you using?

pnpm

What operating system are you using?

Mac

Describe the Bug

Trying to set a cookie within a Response fails because the code in request-transform.js calls a function that is not supported on Vercel's environment.

Unhandled Promise Rejection

TypeError: response.headers.raw is not a function
  at setResponse (file:///var/task/node_modules/.pnpm/@astrojs+vercel@2.3.4/node_modules/@astrojs/vercel/dist/serverless/request-transform.js:61:46)
  at Server.handler (file:///var/task/node_modules/.pnpm/@astrojs+vercel@2.3.4/node_modules/@astrojs/vercel/dist/serverless/entrypoint.js:22:11)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5

Rejection: TypeError: response.headers.raw is not a function
  at process.<anonymous> (file:///var/runtime/index.mjs:1194:17)
  at process.emit (node:events:525:35)
  at process.emit (node:domain:489:12)
  at emit (node:internal/process/promises:149:20)
  at processPromiseRejections (node:internal/process/promises:283:27)
  at process.processTicksAndRejections (node:internal/process/task_queues:96:32)

I'm confused on why the developers used that function instead of the result of .get.

Edit: Whie investigating to try to come up with a PR to fix this, I saw the code is copied from SvelteKit, which might ship a custom implementation of Response and Header that supports the non-standard .raw() call.

Given Headers is associated with fetch, which does not involve setting cookies, it seems it does not account for the exception where multiple Set-Cookie headers can be sent.

I'm still looking into other resources to see if there is a well-established approach, otherwise it seems we'll need to split the values manually, given Header.append will join headers with the same key with a comma.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-axnai7?file=src%2Fpages%2Fredirect.ts

Participation

  • I am willing to submit a pull request for this issue.
@WesSouza WesSouza changed the title @astrojs/vercel issue when returning Response with headers as an object @astrojs/vercel endpoint breaks when sending set-cookie Nov 23, 2022
@bluwy bluwy added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Nov 24, 2022
@bluwy
Copy link
Member

bluwy commented Nov 24, 2022

It does seem like we're block on nodejs/undici#1437. SvelteKit seems to go with the split approach, and I don't think there's a nicer way too, so we might have to do that.

@bluwy
Copy link
Member

bluwy commented Dec 5, 2022

Fixed in #5514

@bluwy bluwy closed this as completed Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

No branches or pull requests

3 participants