[Bug]: BunWebSockets transport not setting CORS headers on matchmaking requests
andrewmunro opened this issue · comments
Context
No response
Bug description
I'm getting CORS errors in my browser because the matchmaking requests are not returning any cors headers.
They are returned correctly for the OPTIONS request, but not for GET or POST...
Issue seems to be here: https://github.com/colyseus/colyseus/blob/master/packages/transport/bun-websockets/src/BunWebSockets.ts#L142
Reproduction
No response
Steps to reproduce
Run a colyseus server configured using bun on a different port from your browser project
import { BunWebSockets } from "@colyseus/bun-websockets";
import { Server, matchMaker } from "colyseus";
// Set custom cors headers - these are only set on options requests :(
matchMaker.controller.getCorsHeaders = function (req) {
return {
"Access-Control-Allow-Origin": "*",
Vary: "*",
};
};
const transport = new BunWebSockets({});
const gameServer = new Server({
transport,
});
await gameServer.listen(DIFFERENT PORT FROM BROWSER HOST)
Environment & Versions
colyseus: 0.15.13
@colyseus/bun-websockets: 0.15.0
Bun: 1.0.18
Workaround until fixed:
const transport = new BunWebSockets({});
transport.expressApp.use((req, res, next) => {
res.set(Object.assign({}, matchMaker.controller.DEFAULT_CORS_HEADERS, matchMaker.controller.getCorsHeaders.call(undefined, req)));
next();
});