Skip to content

Commit 45a5923

Browse files
Merge pull request #450 from adityack477/fix/cors-restrict-origin
fix(server): restrict CORS to allowed origin from env variable
2 parents 1f2f35c + 64c1064 commit 45a5923

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

backend/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SESSION_SECRET=your_strong_random_secret_here
2+
MONGO_URI=mongodb://localhost:27017/github_tracker
3+
PORT=5000
4+
CLIENT_URL=http://localhost:5173

backend/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const logger = require('./logger');
1515
const app = express();
1616

1717
// CORS configuration
18-
app.use(cors('*'));
18+
app.use(cors({
19+
origin: process.env.CLIENT_URL || 'http://localhost:5173',
20+
credentials: true,
21+
}));
1922

2023
// Middleware
2124
app.use(bodyParser.json());

0 commit comments

Comments
 (0)