Skip to content
Open
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
14 changes: 14 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Server
PORT=5000
NODE_ENV=development

# MongoDB
MONGO_URI=mongodb://127.0.0.1:27017/github_tracker

# Session
SESSION_SECRET=your_session_secret_here

# CORS — comma-separated list of allowed frontend origins
# In production, set this to your actual frontend URL(s).
# If not set, defaults to http://localhost:5173
ALLOWED_ORIGINS=http://localhost:5173
12 changes: 9 additions & 3 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ const logger = require('./logger');

const app = express();

// CORS configuration
const allowedOrigins = ['http://localhost:5173', 'https://github-spy.etlify.app'];
// CORS configuration — allowed origins are read from the ALLOWED_ORIGINS env var
// (comma-separated). Falls back to localhost for local development.
const parsedOrigins = process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(',').map(origin => origin.trim()).filter(Boolean)
: [];
const allowedOrigins = parsedOrigins.length > 0 ? parsedOrigins : ['http://localhost:5173'];

app.use(cors({
origin: function (origin, callback) {
// Allow requests with no origin (e.g. server-to-server, curl, mobile apps)
if (!origin || allowedOrigins.indexOf(origin) !== -1) {
callback(null, true);
} else{
} else {
callback(new Error('Blocked by CORS policy'));
}
},
Expand Down