Skip to content

Commit 47a2b38

Browse files
authored
Merge pull request #113 from CS3219-AY2425S1/cloud-fix
allow everyone to access cors
2 parents 7515751 + 39c2bdd commit 47a2b38

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed

api-gateway/src/app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import WebSocket from 'ws';
1313

1414
const app = express();
1515

16-
// Middleware
17-
app.use(cors(config.corsOptions));
18-
app.options('*', cors(config.corsOptions)); // enable pre-flight for all routes
1916
app.use(express.json());
17+
app.use(cors()); // configured so everyone can use
18+
app.options('*', cors());
2019

2120
// Logging middleware
2221
// app.use((req, res, next) => {

api-gateway/src/config/index.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,15 @@
11
import dotenv from 'dotenv';
22
import path from 'path';
3-
import logger from '../utils/logger';
43

54
// Load different env files based on NODE_ENV
65
const envFile = process.env.NODE_ENV === 'production' ? '.env' : '.env.dev';
76
dotenv.config({ path: path.resolve(process.cwd(), envFile) });
87

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-
318
export default {
329
port: process.env.PORT || 8001,
3310
corsOptions: {
34-
origin: getAllowedOrigins(),
11+
origin: process.env.FRONTEND_URL || 'http://localhost:3000',
3512
credentials: true,
36-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
37-
allowedHeaders: ['Content-Type', 'Authorization'],
3813
},
3914
services: {
4015
question: process.env.QUESTION_SERVICE_URL || 'http://localhost:4001',

0 commit comments

Comments
 (0)