X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server.ts;h=9c74ddb694024a77b9332824760e05205feb64c8;hb=c6720f0bf5ff3b28876d5f98eb09d1e83dbed39c;hp=1ba208c280b38ffc3940044387074b3d19530724;hpb=407c4473ad6b1aa30c3d77bd75e3c273d03989b8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server.ts b/server.ts index 1ba208c28..9c74ddb69 100644 --- a/server.ts +++ b/server.ts @@ -26,7 +26,7 @@ const app = express() // ----------- Database ----------- // Do not use barrels because we don't want to load all modules here (we need to initialize database first) import { logger } from './server/helpers/logger' -import { API_VERSION, CONFIG } from './server/initializers/constants' +import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' // Initialize database and models import { database as db } from './server/initializers/database' db.init(false).then(() => onDatabaseInitDone()) @@ -57,10 +57,20 @@ import { apiRouter, clientsRouter, staticRouter } from './server/controllers' // Enable CORS for develop if (isTestInstance()) { - app.use(cors({ - origin: 'http://localhost:3000', - credentials: true - })) + app.use((req, res, next) => { + // These routes have already cors + if ( + req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 && + req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 + ) { + return (cors({ + origin: 'http://localhost:3000', + credentials: true + }))(req, res, next) + } + + return next() + }) } // For the logger @@ -150,7 +160,7 @@ function onDatabaseInitDone () { VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE) logger.info('Server listening on port %d', port) - logger.info('Webserver: %s', CONFIG.WEBSERVER.URL) + logger.info('Web server: %s', CONFIG.WEBSERVER.URL) }) }) }