const express = require('express');
const app = express();
const path = require('path');
const cors = require('cors');

// Middleware
app.use(cors());
app.use(express.json());

// Static folders
app.use('/slides', express.static(path.join(__dirname, 'uploads/slides')));
app.use('/media', express.static(path.join(__dirname, 'uploads/media')));

// Routes
const uploadRoute = require('./routes/upload');
app.use('/upload', uploadRoute);

// const editorRoute = require('./routes/editor');
// app.use('/editor', editorRoute);

const editorSaveRouter = require('./routes/editorSave');
app.use('/', editorSaveRouter); // ✅ FIXED here

// Health check
app.get('/', (req, res) => {
  res.send('Server is running');
});

// Start server
const PORT = 3001;
app.listen(PORT, () => {
  console.log(`Server running at http://localhost:${PORT}`);
});
