diff --git a/lib/index.js b/lib/index.js index df7cd95fbc..bba7b20982 100644 --- a/lib/index.js +++ b/lib/index.js @@ -98,27 +98,21 @@ Server.prototype.checkRequest = function(req, fn) { Server.prototype.serveClient = function(v){ if (!arguments.length) return this._serveClient; this._serveClient = v; - - if (v && !clientSource) { - - var clientSourcePath = path.resolve(__dirname, './../../socket.io-client/dist/socket.io.min.js'); - var clientSourceMapPath = path.resolve(__dirname, './../../socket.io-client/dist/socket.io.min.js.map'); - if(!exists(clientSourcePath)) { - clientSource = read(require.resolve('socket.io-client/dist/socket.io.min.js'), 'utf-8'); - } else { - clientSource = read(clientSourcePath); + var resolvePath = function(file){ + var filepath = path.resolve(__dirname, './../../', file); + if (exists(filepath)) { + return filepath; } - if(!exists(clientSourceMapPath)) { - try { - clientSourceMap = read(require.resolve('socket.io-client/dist/socket.io.js.map'), 'utf-8'); - } catch(err) { - debug('could not load sourcemap file'); - } - } else { - clientSourceMap = read(clientSourceMapPath); + return require.resolve(file); + }; + if (v && !clientSource) { + clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.min.js'), 'utf-8'); + try { + clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.min.js'), 'utf-8'); + } catch(err) { + debug('could not load sourcemap file'); } } - return this; };