// Vercel API route handler for Dad Joke Visualizer
module.exports = async function handler(req, res) {
// Enable CORS for all routes
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT');
res.setHeader('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Authorization');
// Handle OPTIONS requests
if (req.method === 'OPTIONS') {
res.status(200).end();
return;
}
// Serve the main page
if (req.method === 'GET' && req.url === '/') {
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dad Joke Visualizer</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background: #f4f4f4; }
.container { max-width: 800px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
.header { text-align: center; margin-bottom: 30px; }
.nav { text-align: center; margin-top: 20px; }
.nav a { color: #007cba; text-decoration: none; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎭 Dad Joke Visualizer</h1>
<p>Welcome to the Dad Joke Visualizer! Create hilarious dad jokes with AI-generated images.</p>
</div>
<div class="nav">
<p>Use this service through Cursor's MCP integration to generate dad jokes with visualizations!</p>
<p><a href="/api/test">Test API Endpoint</a></p>
</div>
</div>
</body>
</html>
`;
res.status(200).setHeader('Content-Type', 'text/html').send(html);
return;
}
// Test endpoint
if (req.method === 'GET' && req.url === '/api/test') {
res.status(200).json({
success: true,
message: 'Dad Joke Visualizer API is working!',
timestamp: new Date().toISOString(),
version: '1.0.0'
});
return;
}
// Health check
if (req.method === 'GET' && req.url === '/api/health') {
res.status(200).json({
status: 'healthy',
service: 'dad-joke-visualizer',
timestamp: new Date().toISOString(),
version: '1.0.1',
deployment: 'vercel-runtime-fixed'
});
return;
}
// Default response
res.status(404).json({
error: 'Not found',
message: 'This endpoint does not exist',
available_endpoints: ['/', '/api/test', '/api/health']
});
}