Moved CORS logic into httpManager
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import cors from 'cors'
|
||||
import { Application } from 'express'
|
||||
|
||||
import config from '#application/config'
|
||||
import { AuthController } from '#controllers/auth'
|
||||
import { AvatarController } from '#controllers/avatar'
|
||||
import { CacheController } from '#controllers/cache'
|
||||
@ -19,6 +21,16 @@ class HttpManager {
|
||||
* @param app
|
||||
*/
|
||||
public async boot(app: Application) {
|
||||
// Add CORS middleware
|
||||
app.use(
|
||||
cors({
|
||||
origin: config.CLIENT_URL,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Add supported methods
|
||||
allowedHeaders: ['Content-Type', 'Authorization'], // Add allowed headers
|
||||
credentials: true
|
||||
})
|
||||
)
|
||||
|
||||
// Add routes
|
||||
await this.addRoutes(app)
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import { pathToFileURL } from 'url'
|
||||
import { Application } from 'express'
|
||||
import { Server as SocketServer } from 'socket.io'
|
||||
|
||||
import config from '#application/config'
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import Storage from '#application/storage'
|
||||
import { TSocket, UUID } from '#application/types'
|
||||
@ -19,14 +18,7 @@ class SocketManager {
|
||||
* Initialize Socket.IO server
|
||||
*/
|
||||
public async boot(app: Application, http: HTTPServer): Promise<void> {
|
||||
this.io = new SocketServer(http, {
|
||||
cors: {
|
||||
origin: config.CLIENT_URL,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
credentials: true
|
||||
}
|
||||
})
|
||||
this.io = new SocketServer(http)
|
||||
|
||||
// Apply authentication middleware
|
||||
this.io.use(Authentication)
|
||||
|
Reference in New Issue
Block a user