Skip to content

Commit

Permalink
feat: Add CORS headers to WebSocket server.
Browse files Browse the repository at this point in the history
This change adds `Access-Control-Allow-Origin: *` to headers sent by the WebSocket server to enable cross-origin resource sharing (CORS) for incoming WebSocket requests.
  • Loading branch information
frankpagan committed Jun 8, 2023
1 parent 2dc6fcf commit 4701892
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ class SocketServer extends EventEmitter {
super();
this.clients = new Map();
this.prefix = prefix || "crud";

this.wss = new WebSocket.Server({ noServer: true });
this.wss.on('headers', (headers, request) => {
headers.push('Access-Control-Allow-Origin: *');
});

server.on('upgrade', (request, socket, head) => {
if (!this.handleUpgrade(request, socket, head)) {
socket.destroy();
Expand Down

0 comments on commit 4701892

Please sign in to comment.