@@ -5,8 +5,6 @@ const { http, https, path, worker } = require('./dependencies.js');
55const WebSocket = require ( 'ws' ) ;
66const Semaphore = require ( './semaphore.js' ) ;
77
8- const TRANSPORT = { http, https, ws : http , wss : https } ;
9-
108const MIME_TYPES = {
119 html : 'text/html; charset=UTF-8' ,
1210 json : 'application/json; charset=UTF-8' ,
@@ -156,23 +154,21 @@ class Server {
156154 constructor ( config , application ) {
157155 this . config = config ;
158156 this . application = application ;
159- const { ports, host, transport , concurrency, queue } = config ;
157+ const { ports, host, concurrency, queue } = config ;
160158 this . semaphore = new Semaphore ( concurrency , queue . size , queue . timeout ) ;
161159 const { threadId } = worker ;
162160 const port = ports [ threadId - 1 ] ;
163- const lib = TRANSPORT [ transport ] ;
164161 const handler = listener ( application ) ;
165- this . instance = lib . createServer ( { ...application . cert } , handler ) ;
166- if ( transport . startsWith ( 'ws' ) ) {
167- this . ws = new WebSocket . Server ( { server : this . instance } ) ;
168- this . ws . on ( 'connection' , ( connection , req ) => {
169- const client = new Client ( req , null , application , connection ) ;
170- connection . on ( 'message' , message => {
171- const { method, args } = JSON . parse ( message ) ;
172- client . rpc ( method , args ) ;
173- } ) ;
162+ const transport = threadId === 1 ? http : https ;
163+ this . instance = transport . createServer ( { ...application . cert } , handler ) ;
164+ this . ws = new WebSocket . Server ( { server : this . instance } ) ;
165+ this . ws . on ( 'connection' , ( connection , req ) => {
166+ const client = new Client ( req , null , application , connection ) ;
167+ connection . on ( 'message' , message => {
168+ const { method, args } = JSON . parse ( message ) ;
169+ client . rpc ( method , args ) ;
174170 } ) ;
175- }
171+ } ) ;
176172 this . instance . listen ( port , host ) ;
177173 }
178174
0 commit comments