Spaces:
Sleeping
Sleeping
File size: 2,648 Bytes
5386109 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | // Minimal test server for Hugging Face debugging
const express = require('express');
const { createServer } = require('http');
const app = express();
const PORT = parseInt(process.env.PORT) || 7860;
const HOST = '0.0.0.0';
console.log('π Starting minimal test server...');
console.log(`π Port: ${PORT} (type: ${typeof PORT})`);
console.log(`π Host: ${HOST}`);
console.log(`π NODE_ENV: ${process.env.NODE_ENV}`);
// Basic middleware
app.use((req, res, next) => {
console.log(`π₯ ${req.method} ${req.url} from ${req.ip}`);
next();
});
app.get('/health', (req, res) => {
console.log('β
Health check requested');
res.status(200).json({
status: 'OK',
timestamp: new Date().toISOString(),
message: 'Test server is accessible!',
port: PORT,
host: HOST,
env: process.env.NODE_ENV
});
});
app.get('/', (req, res) => {
console.log('π Root path requested');
res.status(200).send(`
<!DOCTYPE html>
<html>
<head>
<title>edi.chat Test Server</title>
<meta charset="utf-8">
</head>
<body style="font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px;">
<h1>π Test Server is Working!</h1>
<p><strong>β
External connection successful!</strong></p>
<p>Server: ${HOST}:${PORT}</p>
<p>Environment: ${process.env.NODE_ENV || 'development'}</p>
<p>Timestamp: ${new Date().toISOString()}</p>
<hr>
<p><a href="/health">π Health Check</a></p>
<p><a href="/test">π§ͺ Test Endpoint</a></p>
</body>
</html>
`);
});
app.get('/test', (req, res) => {
console.log('π§ͺ Test endpoint requested');
res.status(200).json({
message: 'Test endpoint working!',
server_info: {
port: PORT,
host: HOST,
env: process.env.NODE_ENV,
uptime: process.uptime(),
memory: process.memoryUsage()
}
});
});
// Create HTTP server explicitly
const server = createServer(app);
server.listen(PORT, HOST, () => {
console.log(`π TEST SERVER STARTED SUCCESSFULLY!`);
console.log(`π‘ Listening on: http://${HOST}:${PORT}`);
console.log(`π Environment: ${process.env.NODE_ENV || 'development'}`);
console.log(`π― Server is ready for external connections!`);
console.log(`β° Started at: ${new Date().toISOString()}`);
});
server.on('error', (err) => {
console.error('β Server error:', err);
});
// Handle shutdown gracefully
process.on('SIGTERM', () => {
console.log('π SIGTERM received, shutting down gracefully...');
server.close(() => {
console.log('β
Server closed');
process.exit(0);
});
}); |