Skip to content

Commit

Permalink
Merge pull request #25 from Crazy-Cow/CD-72
Browse files Browse the repository at this point in the history
fix: cors 설정 옵션 추가2 [CD-72]
  • Loading branch information
ddubbu-dev authored Nov 15, 2024
2 parents ae0026e + b13a09a commit d804f6c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import routes from './routes'
import swaggerUi from 'swagger-ui-express'
import swaggerDocument from './docs/swagger-output.json'
import { initSocket } from './socket'
import { Server } from 'socket.io'
import { Server, ServerOptions } from 'socket.io'
import { initInGmaeSocket } from './game/server'

const port = process.env.PORT

const app: Express = express()
app.use(cors({ origin: '*' }))
app.use(cors())
app.use(cookieParser())
app.use(express.json())
app.use('/example', routes.example)
Expand All @@ -27,8 +27,7 @@ const server = app.listen(port, () => {
})

const allowedOrigins = ['http://localhost:5173']

const io = new Server(server, {
const socketCorsOption: Partial<ServerOptions> = {
cors: {
origin: (origin, callback) => {
if (!origin || allowedOrigins.includes(origin)) {
Expand All @@ -38,8 +37,12 @@ const io = new Server(server, {
}
},
methods: ['GET', 'POST'],
credentials: true,
},
})
transports: ['websocket', 'polling'],
}

const io = new Server(server, socketCorsOption)

initSocket(io)
initInGmaeSocket(io)
Expand Down

0 comments on commit d804f6c

Please sign in to comment.