Skip to content

Commit

Permalink
Merge pull request #24 from Crazy-Cow/CD-72
Browse files Browse the repository at this point in the history
fix: cors allow origin 지정 (local 우선) [CD-72]
  • Loading branch information
ddubbu-dev authored Nov 15, 2024
2 parents 150ff2e + e07686b commit ae0026e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ const server = app.listen(port, () => {
console.log(`[2] Server runs at <http://localhost>:${port}`)
})

const io = new Server(server, { cors: { origin: '*' } })
const allowedOrigins = ['http://localhost:5173']

const io = new Server(server, {
cors: {
origin: (origin, callback) => {
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'), false)
}
},
methods: ['GET', 'POST'],
},
})

initSocket(io)
initInGmaeSocket(io)

Expand Down

0 comments on commit ae0026e

Please sign in to comment.