Prima importazione
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
|
||||
const ticketsRouter = require('./routes/tickets');
|
||||
const lookupsRouter = require('./routes/lookups');
|
||||
const dashboardRouter = require('./routes/dashboard');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Serve static frontend
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// API Routes
|
||||
app.use('/api/tickets', ticketsRouter);
|
||||
app.use('/api', lookupsRouter);
|
||||
app.use('/api/dashboard', dashboardRouter);
|
||||
|
||||
// SPA fallback — serve index.html for all non-API routes
|
||||
app.get('*', (req, res) => {
|
||||
if (!req.path.startsWith('/api')) {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
}
|
||||
});
|
||||
|
||||
// Error handler
|
||||
app.use((err, req, res, next) => {
|
||||
console.error('Server error:', err);
|
||||
res.status(500).json({ error: 'Internal server error', message: err.message });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`\n ⚡ OTRS Turbo running at http://localhost:${PORT}\n`);
|
||||
});
|
||||
Reference in New Issue
Block a user