@@ -345,28 +345,32 @@ var SocketIOServer = function(spec, portal, observer) {
345345 // A Socket.IO server has a unique reconnection key. Client cannot reconnect to another Socket.IO server in the cluster.
346346 var reconnection_key = require ( 'crypto' ) . randomBytes ( 64 ) . toString ( 'hex' ) ;
347347 var sioOptions = { } ;
348+ // TODO: remove allowEIO3
349+ sioOptions . allowEIO3 = true ;
348350 if ( spec . pingInterval ) {
349351 sioOptions . pingInterval = spec . pingInterval * 1000 ;
350352 }
351353 if ( spec . pingTimeout ) {
352354 sioOptions . pingTimeout = spec . pingTimeout * 1000 ;
353355 }
354-
355- var startInsecure = function ( port , cors ) {
356- var server = require ( 'http' ) . createServer ( ) . listen ( port ) ;
357- io = require ( 'socket.io' ) . listen ( server , sioOptions ) ;
358- io . origins ( ( origin , callback ) => {
359- if ( cors . indexOf ( origin ) < 0 && cors . indexOf ( '*' ) < 0 ) {
356+ if ( spec . cors ) {
357+ sioOptions . cors = { credentials : true } ;
358+ sioOptions . cors . origin = ( origin , callback ) => {
359+ if ( spec . cors . indexOf ( origin ) < 0 && spec . cors . indexOf ( '*' ) < 0 ) {
360360 return callback ( 'origin not allowed' , false ) ;
361361 }
362-
363362 callback ( null , true ) ;
364- } ) ;
363+ } ;
364+ }
365+
366+ var startInsecure = function ( port ) {
367+ var server = require ( 'http' ) . createServer ( ) . listen ( port ) ;
368+ io = require ( 'socket.io' ) ( server , sioOptions ) ;
365369 run ( ) ;
366370 return Promise . resolve ( 'ok' ) ;
367371 } ;
368372
369- var startSecured = function ( port , cors , keystorePath , forceTlsv12 ) {
373+ var startSecured = function ( port , keystorePath , forceTlsv12 ) {
370374 return new Promise ( function ( resolve , reject ) {
371375 var cipher = require ( './cipher' ) ;
372376 var keystore = path . resolve ( path . dirname ( keystorePath ) , cipher . kstore ) ;
@@ -378,13 +382,7 @@ var SocketIOServer = function(spec, portal, observer) {
378382 option . secureOptions = ( constants . SSL_OP_NO_TLSv1 | constants . SSL_OP_NO_TLSv1_1 ) ;
379383 }
380384 var server = require ( 'https' ) . createServer ( option ) . listen ( port ) ;
381- io = require ( 'socket.io' ) . listen ( server , sioOptions ) ;
382- io . origins ( ( origin , callback ) => {
383- if ( cors . indexOf ( origin ) < 0 && cors . indexOf ( '*' ) < 0 ) {
384- return callback ( 'origin not allowed' , false ) ;
385- }
386- callback ( null , true ) ;
387- } ) ;
385+ io = require ( 'socket.io' ) ( server , sioOptions ) ;
388386 run ( ) ;
389387 resolve ( 'ok' ) ;
390388 } else {
@@ -430,9 +428,9 @@ var SocketIOServer = function(spec, portal, observer) {
430428
431429 that . start = function ( ) {
432430 if ( ! spec . ssl ) {
433- return startInsecure ( spec . port , spec . cors ) ;
431+ return startInsecure ( spec . port ) ;
434432 } else {
435- return startSecured ( spec . port , spec . cors , spec . keystorePath , spec . forceTlsv12 ) ;
433+ return startSecured ( spec . port , spec . keystorePath , spec . forceTlsv12 ) ;
436434 }
437435 } ;
438436
0 commit comments