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