๋กœ์ผ“๐Ÿพ
article thumbnail

 

์›น์„ ๊ฐœ๋ฐœํ•˜๋ฉด ํ•œ๋ฒˆ์€ ๊ผญ Cors ๋ฌธ์ œ๋ฅผ ๋งž๋‹ฅ๋œจ๋ฆฝ๋‹ˆ๋‹ค. ์ฑ„ํŒ… ์„œ๋ฒ„๋ฅผ aws๋กœ ๊ตฌ์ถ•ํ•˜๊ณ , ๋กœ์ปฌ์—์„œ ์ฑ„ํŒ… ์„œ๋ฒ„๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฑ„ํŒ…์„ ๊ฐœ๋ฐœํ•˜๊ณ  ์žˆ๋Š”๋ฐ ์—ญ์‹œ๋‚˜ ๋„๋ฉ”์ธ์ด ๋‹ฌ๋ผ Cors ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

Node.js ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ค‘ 'Cors'๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์ง€๋งŒ Socket.io์—์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ๋ผ์„œ ์ด๊ฑธ๋กœ๋Š” ํ•ด๊ฒฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณธ ๊ฒฐ๊ณผ Socker.io ๊ณต์‹๋ฌธ์„œ์— ๋‹คํ–‰ํžˆ ์ž˜ ์„ค๋ช…๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

"socket.io": "^4.1.3" ๋ฒ„์ „ ๊ธฐ์ค€์ž…๋‹ˆ๋‹ค.

 

  const io = require("socket.io")(server, {
    cors: {
      origin: "*",
      methods: ["GET", "POST"]
    }
  });

 ์œ„ ์ฝ”๋“œ๋ฅผ server-side์— ์ž‘์„ฑํ•ด์ฃผ์‹œ๊ณ , client-side์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด์ฃผ์‹œ๋ฉด ํ•ด๊ฒฐ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

var socket = io.connect(`์ฑ„ํŒ…์„œ๋ฒ„ ์ฃผ์†Œ`,{
        cors: { origin: '*' }
      });

์˜ˆ์ œ ์ฝ”๋“œ๋“ค์€ ๋ชจ๋“  ๋„๋ฉ”์ธ์„ ํ—ˆ๋ฝํ•˜์ง€๋งŒ ๋ณด์•ˆ์ƒ ๋ฌธ์ œ๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ ์‹ค์ œ๋กœ ๋ฐฐํฌํ• ๋• ๋”ฑ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

์•„๋ž˜ ๋งํฌ๋Š” Socket.io ๊ณต์‹ ๋ฌธ์„œ ๋งํฌ์ž…๋‹ˆ๋‹ค.

 

Introduction

What Socket.IO isSocket.IO is a library that enables real-time, bidirectional and event-based communication between the browser and the server. It consists of: a Node.js server: Source | API a Javasc

socket.io

 

profile on loading

Loading...