const http = require('http');
const httpProxy = require('http-proxy');

const proxy = httpProxy.createProxyServer({
  target: 'https://us1.trinsic.sip.twilio.com',
  changeOrigin: true,
  ws: true
});

const server = http.createServer((req, res) => {
  console.log('➡️', req.url);
  if (req.url === '/health') {
    res.end('OK');
    return;
  }
  proxy.web(req, res);
});

server.on('upgrade', (req, socket, head) => {
  proxy.ws(req, socket, head);
});

const PORT = 3005;  // PORTA DIFERENTE!
server.listen(PORT, () => {
  console.log(`✅ Proxy rodando na porta ${PORT}`);
});
