File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,21 @@ module.exports = function(/** @type Red */ RED) {
251251 const uib_socketPath = tilib . urlJoin ( httpNodeRoot , uib . moduleName , 'vendor' , 'socket.io' )
252252
253253 log . trace ( '[uibuilder:Module] Socket.IO initialisation - Socket Path=' , uib_socketPath )
254- var io = socketio . listen ( RED . server , { 'path' : uib_socketPath } ) // listen === attach
254+ let ioOptions = {
255+ 'path' : uib_socketPath ,
256+ // for CORS need to handle preflight request explicitly 'cause there's an
257+ // Allow-Headers:X-ClientId in there. see https://socket.io/docs/v2/handling-cors/
258+ handlePreflightRequest : ( req , res ) => {
259+ res . writeHead ( 204 , {
260+ "Access-Control-Allow-Origin" : req . headers [ "origin" ] ,
261+ "Access-Control-Allow-Methods" : "GET,POST" ,
262+ "Access-Control-Allow-Headers" : "X-ClientId" ,
263+ "Access-Control-Allow-Credentials" : true ,
264+ } ) ;
265+ res . end ( ) ;
266+ } ,
267+ }
268+ var io = socketio . listen ( RED . server , ioOptions ) // listen === attach
255269 // @ts -ignore
256270 io . set ( 'transports' , [ 'polling' , 'websocket' ] )
257271
You can’t perform that action at this time.
0 commit comments