-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Bun.serve not supporting CORS #5466
Comments
Go with your alternative |
Bun.serve({
fetch(req) {
const res = new Response('hello world');
res.headers.set('Access-Control-Allow-Origin', '*');
res.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
// add Access-Control-Allow-Headers if needed
return res;
},
});
|
As @controversial mentioned, CORS is possible using |
If you've added these headers to
and are still getting CORS issues via a browser your To solve this, I created a
|
You approach @lliamscholtz did work out for me with a slight change as the client had a
|
Or extend the Response: import { BodyInit, ResponseInit } from "undici-types";
export class ClientResponse extends Response {
constructor(body?: BodyInit, init?: ResponseInit) {
super(body, init);
this.headers.set("Access-Control-Allow-Origin", "*");
this.headers.set("Access-Control-Allow-Methods", "OPTIONS, GET");
this.headers.set("Access-Control-Allow-Headers", "Content-Type");
}
} |
What is the problem this feature would solve?
Handle CORS, which is one of the basics of a HTTP server. Without CORS settings Bun.serve is kind of useless.
What is the feature you are proposing to solve the problem?
Support CORS settings
What alternatives have you considered?
Fall back to Express
The text was updated successfully, but these errors were encountered: