Socket.io: Server.prototype.serveClient๋Š” ์›นํŒฉ์—์„œ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2017๋…„ 07์›” 29์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: socketio/socket.io

  • [x] ๋ฒ„๊ทธ ๋ณด๊ณ 

ํ˜„์žฌ ํ–‰๋™

์ด ํ•จ์ˆ˜๋Š” ์ƒ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ socket.io-client๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ webpack์„ ์‚ฌ์šฉํ•˜์—ฌ webpack์„ ์‚ฌ์šฉํ•˜๋Š” nodejs ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ๋ฌถ๋Š” ๊ฒฝ์šฐ. ์ด๊ฒƒ์€ node_modules์˜ socket.io-client์— ๋Œ€ํ•œ ์ƒ๋Œ€ ๊ฒฝ๋กœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

์‹คํ–‰ ์ค‘์ธ ๋…ธ๋“œ๋Š” ๋‹ค์Œ ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ค๋ฅ˜: "." ๋ชจ๋“ˆ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์žฌํ˜„ ๋‹จ๊ณ„(ํ˜„์žฌ ๋™์ž‘์ด ๋ฒ„๊ทธ์ธ ๊ฒฝ์šฐ)

์ฐธ๊ณ  : ๋น ๋ฅธ ๋‹ต๋ณ€์„ ์–ป๋Š” ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์€ ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ ๋ฐ”์ด์˜ฌ๋ฆฐ ์„ ๋ถ„๊ธฐํ•˜์—ฌ ์‹คํŒจํ•œ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋ฒˆ๋“ค์˜ ์ปดํŒŒ์ผ๋œ ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Server.prototype.serveClient = function(v){
  if (!arguments.length) return this._serveClient;
  this._serveClient = v;
  var resolvePath = function(file){
    var filepath = path.resolve(__dirname, './../../', file);
    if (exists(filepath)) {
      return filepath;
    }
    return /*require.resolve*/(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
  };
  if (v && !clientSource) {
    clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
    try {
      clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
    } catch(err) {
      debug('could not load sourcemap file');
    }
  }
  return this;
};

์˜ˆ์ƒ๋˜๋Š” ํ–‰๋™

ํŒจํ‚ค์ง€๋Š” webpack์œผ๋กœ ์ž˜ ์ปดํŒŒ์ผ๋˜๊ณ  ์›ํ™œํ•˜๊ฒŒ ์‹คํ–‰๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์„ค์ •

  • ์šด์˜ ์ฒด์ œ: ์œˆ๋„์šฐ
  • ๋ธŒ๋ผ์šฐ์ €: N/A
  • socket.io ๋ฒ„์ „:
    "์›นํŒฉ": "^3.3.0"
    "socket.io": "^2.0.3",
    "socket.io-client": "^2.0.3"

    ๊ธฐํƒ€ ์ •๋ณด(์˜ˆ: ์Šคํƒ ์ถ”์ , ๊ด€๋ จ ๋ฌธ์ œ, ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์ œ์•ˆ)

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

socket.io์˜ _serving client files_ feat.

const io = require('socket.io')(httpServer, { serveClient: false })

์ด์ƒ์ ์ด์ง€๋Š” ์•Š์ง€๋งŒ ์ ์–ด๋„ ๋ฒˆ๋“ค์€ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  4 ๋Œ“๊ธ€

๊ฐ™์€ ๋ฌธ์ œ

socket.io์˜ _serving client files_ feat.

const io = require('socket.io')(httpServer, { serveClient: false })

์ด์ƒ์ ์ด์ง€๋Š” ์•Š์ง€๋งŒ ์ ์–ด๋„ ๋ฒˆ๋“ค์€ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

๋‚˜๋Š” ์ด๊ฒƒ์ด ๊ฐ™์€ ์˜ค๋ฅ˜๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. webpack์„ ์‚ฌ์šฉํ•˜์—ฌ ๋Ÿฐํƒ€์ž„์— ์–ป์Šต๋‹ˆ๋‹ค.

Error: Cannot find module 'socket.io-client/dist/socket.io.js'

๋‚ด๊ฐ€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” socket.io ์ž๊ธฐ๋ฅผํ•˜์ง€๋งŒ์˜ ์ข…์†์„ฑ์˜ androidjs

ํ›„์† ํŒจ์น˜์—์„œ raw-loader ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

diff --git a/node_modules/socket.io/lib/index.js b/node_modules/socket.io/lib/index.js
index 5287e4e..9ee4577
--- a/node_modules/socket.io/lib/index.js
+++ b/node_modules/socket.io/lib/index.js
@@ -113,9 +113,9 @@ Server.prototype.serveClient = function(v){
     return require.resolve(file);
   };
   if (v && !clientSource) {
-    clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
+    clientSource = require( 'raw-loader!socket.io-client/dist/socket.io.js');
     try {
-      clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
+      clientSourceMap = require( 'raw-loader!socket.io-client/dist/socket.io.js.map');
     } catch(err) {
       debug('could not load sourcemap file');
     }

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰