diff options
Diffstat (limited to 'server.ts')
-rw-r--r-- | server.ts | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -26,7 +26,7 @@ const app = express() | |||
26 | // ----------- Database ----------- | 26 | // ----------- Database ----------- |
27 | // Do not use barrels because we don't want to load all modules here (we need to initialize database first) | 27 | // Do not use barrels because we don't want to load all modules here (we need to initialize database first) |
28 | import { logger } from './server/helpers/logger' | 28 | import { logger } from './server/helpers/logger' |
29 | import { API_VERSION, CONFIG } from './server/initializers/constants' | 29 | import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' |
30 | // Initialize database and models | 30 | // Initialize database and models |
31 | import { database as db } from './server/initializers/database' | 31 | import { database as db } from './server/initializers/database' |
32 | db.init(false).then(() => onDatabaseInitDone()) | 32 | db.init(false).then(() => onDatabaseInitDone()) |
@@ -57,10 +57,20 @@ import { apiRouter, clientsRouter, staticRouter } from './server/controllers' | |||
57 | 57 | ||
58 | // Enable CORS for develop | 58 | // Enable CORS for develop |
59 | if (isTestInstance()) { | 59 | if (isTestInstance()) { |
60 | app.use(cors({ | 60 | app.use((req, res, next) => { |
61 | origin: 'http://localhost:3000', | 61 | // These routes have already cors |
62 | credentials: true | 62 | if ( |
63 | })) | 63 | req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 && |
64 | req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 | ||
65 | ) { | ||
66 | return (cors({ | ||
67 | origin: 'http://localhost:3000', | ||
68 | credentials: true | ||
69 | }))(req, res, next) | ||
70 | } | ||
71 | |||
72 | return next() | ||
73 | }) | ||
64 | } | 74 | } |
65 | 75 | ||
66 | // For the logger | 76 | // For the logger |