Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT=5000
MONGO_URI=mongodb://localhost:27017/githubTracker
SESSION_SECRET=your-secret-key
ALLOWED_ORIGINS=http://localhost:5173
17 changes: 15 additions & 2 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ require('./config/passportConfig');

const app = express();

// CORS configuration
app.use(cors('*'));
// CORS configuration — restrict to known frontend origins only
const allowedOrigins = (process.env.ALLOWED_ORIGINS || 'http://localhost:5173')
.split(',')
.map(o => o.trim());

app.use(cors({
origin: (origin, callback) => {
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true,
}));

// Middleware
app.use(bodyParser.json());
Expand Down
Loading