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

When the API returns the HTTP response for fetch, the API crashes #11921

Open
1 task
ccbikai opened this issue Sep 5, 2024 · 3 comments
Open
1 task

When the API returns the HTTP response for fetch, the API crashes #11921

ccbikai opened this issue Sep 5, 2024 · 3 comments
Labels
- P2: has workaround Bug, but has workaround (priority)

Comments

@ccbikai
Copy link

ccbikai commented Sep 5, 2024

Astro Info

Astro                    v4.15.2
Node                     v18.18.2
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

Chrome

Describe the Bug

https://github.com/ccbikai/astro-debug

How to reproduce:

npm run dev

Visit http://localhost:4321/api/https://http.im/status/200, no error reported

Access http://localhost:4321/api/https://http.im/status/500, and encounter an error TypeError: immutable.

What's the expected result?

only return 500 http response

Link to Minimal Reproducible Example

https://github.com/ccbikai/astro-debug

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 5, 2024
@ccbikai
Copy link
Author

ccbikai commented Sep 5, 2024

@liruifengv Communication

@ascorbic
Copy link
Contributor

ascorbic commented Sep 5, 2024

The issue here is that the Response returned from a fetch() is immutable, but Astro expects to be able to add headers to it. You can fix it by returning a new Response with the response:

export async function GET({ request, params }) {
  const response = await fetch(params.url, request)
  return new Response(response.body, response)
}

It might be nice if Astro handled this itself, but I'm not sure how widespread this is likely to be.

@ascorbic ascorbic added - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged labels Sep 5, 2024
@ccbikai
Copy link
Author

ccbikai commented Sep 6, 2024

@ascorbic Thank you for your help, your code works fine now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority)
Projects
None yet
Development

No branches or pull requests

2 participants