const express = require('express');
const cors = require('cors');
const path = require('path');
require('dotenv').config({ 
  path: path.resolve(__dirname, '.env') 
});

const app = express();
const port = process.env.TYPEFORM_PORT || 3008;

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

// Import routes
const typeformRoutes = require('./routes/typeform.routes');

// Use routes
app.use('/api/typeform', typeformRoutes);

// Error handling middleware
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).json({ error: 'Something went wrong!' });
});

// Start server
app.listen(port, () => {
  console.log(`Typeform API server running on port ${port}`);
});

module.exports = app; 