Skip to content
Merged
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
6 changes: 6 additions & 0 deletions stellar-payment-platform/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/stellar_tags?schema=
# --- Admin API Key -------------------------------------------------------------
# Key used to authenticate with protected admin endpoints (e.g., blocking addresses)
ADMIN_API_KEY="your-secure-admin-api-key-here"

# --- CORS ------------------------------------------------------------------
# Extra origins allowed to call the API, beyond the built-in localhost/vercel
# defaults. Accepts a single origin or a comma-separated list.
# CORS_ALLOWED_ORIGINS="https://example.com,https://staging.example.com"
# VITE_API_BASE="https://api.yourdomain.com"
10 changes: 9 additions & 1 deletion stellar-payment-platform/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,34 @@ app.set('query parser', 'simple');
const PORT = process.env.PORT || 5000;
const STELLAR_TAG_DOMAIN = process.env.STELLAR_TAG_DOMAIN;

const envOrigins = process.env.CORS_ALLOWED_ORIGINS
? process.env.CORS_ALLOWED_ORIGINS.split(',').map(o => o.trim())
: [];

const allowedOrigins = [
'http://localhost:5173',
'http://localhost:3000',
'https://stellar-tags.vercel.app',
STELLAR_TAG_DOMAIN,
process.env.VITE_API_BASE,
...envOrigins,
].filter(Boolean);

const corsOptions = {
origin: (origin, callback) => {
if (!origin || allowedOrigins.includes(origin)) {
return callback(null, true);
}
return callback(null, false);
return callback(new Error('Not allowed by CORS'));
},
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
credentials: true,
optionsSuccessStatus: 204,
};

app.use(cors(corsOptions));

// Apply metrics middleware to track all HTTP requests
app.use(metricsMiddleware);

Expand Down
Loading