|
1 | 1 | import dotenv from 'dotenv'; |
2 | 2 | import path from 'path'; |
3 | | -import logger from '../utils/logger'; |
4 | 3 |
|
5 | 4 | // Load different env files based on NODE_ENV |
6 | 5 | const envFile = process.env.NODE_ENV === 'production' ? '.env' : '.env.dev'; |
7 | 6 | dotenv.config({ path: path.resolve(process.cwd(), envFile) }); |
8 | 7 |
|
9 | | -const getAllowedOrigins = () => { |
10 | | - if (process.env.NODE_ENV === 'production') { |
11 | | - const frontendUrl = process.env.FRONTEND_URL; |
12 | | - if (!frontendUrl) { |
13 | | - logger.warn('FRONTEND_URL environment variable not set in production'); |
14 | | - return ['http://localhost:3000']; |
15 | | - } |
16 | | - // If frontendUrl already includes protocol, use it as is |
17 | | - if ( |
18 | | - frontendUrl.startsWith('http://') || |
19 | | - frontendUrl.startsWith('https://') |
20 | | - ) { |
21 | | - const httpVersion = frontendUrl; |
22 | | - const httpsVersion = frontendUrl.replace('http://', 'https://'); |
23 | | - return [httpVersion, httpsVersion]; |
24 | | - } |
25 | | - // Otherwise, add protocols (backward compatibility) |
26 | | - return [`http://${frontendUrl}`, `https://${frontendUrl}`]; |
27 | | - } |
28 | | - return ['http://localhost:3000']; |
29 | | -}; |
30 | | - |
31 | 8 | export default { |
32 | 9 | port: process.env.PORT || 8001, |
33 | 10 | corsOptions: { |
34 | | - origin: getAllowedOrigins(), |
| 11 | + origin: process.env.FRONTEND_URL || 'http://localhost:3000', |
35 | 12 | credentials: true, |
36 | | - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], |
37 | | - allowedHeaders: ['Content-Type', 'Authorization'], |
38 | 13 | }, |
39 | 14 | services: { |
40 | 15 | question: process.env.QUESTION_SERVICE_URL || 'http://localhost:4001', |
|
0 commit comments