Spaces:
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);
  });
});