CORS für Hallenplaner-API auf halle.tkdduisburg.de erweitern

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Klaas Börgmann 2026-07-21 12:22:38 +02:00
parent a518c6bbc4
commit bd3593fb48
1 changed files with 15 additions and 0 deletions

15
app.js
View File

@ -93,6 +93,21 @@ const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
// CORS für Hallenplaner-API
const ALLOWED_ORIGINS = ['https://halle.tkdduisburg.de'];
app.use('/api/layouts', (req, res, next) => {
const origin = req.headers.origin;
if (ALLOWED_ORIGINS.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
}
if (req.method === 'OPTIONS') {
return res.sendStatus(204);
}
next();
});
// Api für Hallenplaner
app.get('/api/layouts', async (req, res) => {
try {