// Minimal Express test for CloudLinux Passenger
// CloudLinux requires explicit server.listen() call

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

// Handle both root and /CompareKit paths
app.get(['/', '/CompareKit', '/CompareKit/'], (req, res) => {
  res.send(`
    <h1 style="color: green;">✅ Express Works!</h1>
    <p><strong>Node:</strong> ${process.version}</p>
    <p><strong>Request Path:</strong> ${req.path}</p>
    <hr>
    <p><a href="/CompareKit/test-canvas">Test Canvas (will likely fail)</a></p>
    <p><a href="/CompareKit/test-sharp">Test Sharp (will likely fail)</a></p>
  `);
});

app.get(['/test-canvas', '/CompareKit/test-canvas'], (req, res) => {
  try {
    require('canvas');
    res.send('<h1 style="color: green;">✅ Canvas loaded OK!</h1><p>Canvas module is available on this server!</p>');
  } catch (e) {
    res.send(`<h1 style="color: red;">❌ Canvas FAILED</h1><p><strong>Error:</strong> ${e.message}</p><hr><pre>${e.stack}</pre>`);
  }
});

app.get(['/test-sharp', '/CompareKit/test-sharp'], (req, res) => {
  try {
    require('sharp');
    res.send('<h1 style="color: green;">✅ Sharp loaded OK!</h1><p>Sharp module is available on this server!</p>');
  } catch (e) {
    res.send(`<h1 style="color: red;">❌ Sharp FAILED</h1><p><strong>Error:</strong> ${e.message}</p><hr><pre>${e.stack}</pre>`);
  }
});

// CloudLinux Passenger needs explicit listen() call
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log('Express running on port ' + port);
});
