// Minimal test app to diagnose Passenger issues
// This version has NO canvas or sharp dependencies

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

app.get('/', (req, res) => {
  res.send(`
    <h1>CompareKit Test Page</h1>
    <p>If you can see this, Express is working!</p>
    <p>Node.js version: ${process.version}</p>
    <p>Environment: ${process.env.NODE_ENV || 'development'}</p>
    <p><a href="/health">Health Check</a></p>
  `);
});

app.get('/health', (req, res) => {
  res.json({
    status: 'ok',
    message: 'Basic Express app working',
    node_version: process.version,
    dependencies_loaded: {
      express: true
    }
  });
});

app.get('/test-dependencies', (req, res) => {
  const results = {
    express: 'OK',
    cors: 'not tested',
    canvas: 'not tested',
    sharp: 'not tested'
  };

  // Test if we can load each module
  try {
    require('cors');
    results.cors = 'OK';
  } catch (e) {
    results.cors = 'FAILED: ' + e.message;
  }

  try {
    require('canvas');
    results.canvas = 'OK';
  } catch (e) {
    results.canvas = 'FAILED: ' + e.message;
  }

  try {
    require('sharp');
    results.sharp = 'OK';
  } catch (e) {
    results.sharp = 'FAILED: ' + e.message;
  }

  res.json({
    status: 'Dependency Test Results',
    results: results
  });
});

// Export for Passenger
module.exports = app;
