const express = require('express');
const http = require('http');
const socketIo = require('socket.io');

const app = express();
const server = http.createServer(app);
const io = socketIo(server);

app.use(express.text({ type: '*/*' }));

app.use(express.static('public'));

app.post('/send', (req, res) => {
  const classification = req.body.trim();
  console.log('Received classification:', classification);

  io.emit('classification', classification);

  res.sendStatus(200);
});

const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});
