1
0
forked from noxious/server

Moved CORS logic into httpManager

This commit is contained in:
2025-01-21 14:58:55 +01:00
parent 0ba79c2299
commit 189fd39377
3 changed files with 79 additions and 75 deletions

View File

@ -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)
}

View File

@ -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)