You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement a CORS middleware in Bun that adds some additional headers to all responses. This is proving to be quite difficult at the moment. I see you have this example but that's not quite enough to fully handle CORS headers. I'm trying to do something more like this.
I'm wondering if it would be possible for middleware in Bun to be able to extend the Response object somehow. At the moment, await next() in middleware returns undefined. It would be great if it returned the response of the promise chain.
Ideally, I would like to write a middleware like this:
importtype{NextFunction}from'node-file-router';constheaders=async(req: Request,next: NextFunction)=>{constres=awaitnext();// Ensure all API requests always return these headersres.headers.set('Access-Control-Allow-Origin','*');res.headers.set('Access-Control-Allow-Methods','GET, POST, PUT, DELETE, OPTIONS');returnres;};exportdefaultheaders;
Do you think this would be possible to add support for?
The text was updated successfully, but these errors were encountered:
Cool, sure, I had the same thought earlier as well! It will be delivered tomorrow.
One thing to keep in mind: if your CORS middleware is positioned as follows:
[useLogger] -> [useCors] -> [useAuth].
@EvHaus Hey! I've released version 0.6.0 with this feature :) Please feel free to reach out if you have any issues or additional suggestions. The documentation can be found here, and it aligns with what you described earlier.
👋 Hey. It's me again.
I'm trying to implement a CORS middleware in Bun that adds some additional headers to all responses. This is proving to be quite difficult at the moment. I see you have this example but that's not quite enough to fully handle CORS headers. I'm trying to do something more like this.
I'm wondering if it would be possible for middleware in Bun to be able to extend the
Response
object somehow. At the moment,await next()
in middleware returnsundefined
. It would be great if it returned the response of the promise chain.Ideally, I would like to write a middleware like this:
Do you think this would be possible to add support for?
The text was updated successfully, but these errors were encountered: