51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
// Express alkalmazás konfiguráció
|
|
import express from 'express';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
import { createRouter } from './routes/index.js';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
const app = express();
|
|
|
|
// Nginx proxy mögött a valódi kliens IP-t az X-Forwarded-For fejlécből veszi
|
|
app.set('trust proxy', 1);
|
|
|
|
// JSON és form body parser (webhook payloadokhoz)
|
|
app.use(express.json({ limit: '1mb' }));
|
|
app.use(express.urlencoded({ extended: true, limit: '1mb' }));
|
|
|
|
// Nyers body mentése más content-type esetén (pl. text/plain, application/xml)
|
|
app.use((req, _res, next) => {
|
|
const ct = req.headers['content-type'] || '';
|
|
// Ha már parseolta az express (json/urlencoded), nem kell külön
|
|
if (ct.includes('application/json') || ct.includes('application/x-www-form-urlencoded')) {
|
|
return next();
|
|
}
|
|
let raw = '';
|
|
req.setEncoding('utf8');
|
|
req.on('data', chunk => { raw += chunk; });
|
|
req.on('end', () => {
|
|
req.rawBody = raw;
|
|
next();
|
|
});
|
|
});
|
|
|
|
// Statikus fájlok kiszolgálása (Vite build output)
|
|
app.use(express.static(join(__dirname, '../public')));
|
|
|
|
// API és webhook route-ok
|
|
app.use('/', createRouter());
|
|
|
|
// SPA fallback - minden egyéb kérésre az index.html-t küldi vissza
|
|
app.get('*', (_req, res) => {
|
|
const indexPath = join(__dirname, '../public/index.html');
|
|
res.sendFile(indexPath, (err) => {
|
|
if (err) {
|
|
res.status(503).send('A frontend még nincs buildeve. Futtasd: npm run build');
|
|
}
|
|
});
|
|
});
|
|
|
|
export default app;
|