File size: 1,496 Bytes
06bc801
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const express = require('express');
const cors = require('cors'); // นำเข้า CORS
const app = express();
const PORT = 7860; // Port บังคับสำหรับ Hugging Face Spaces

// --- การตั้งค่า Middleware ---

// อนุญาตให้ทุกคน (ทุก Origin) เข้าถึง API นี้ได้
app.use(cors()); 

// ทำให้ Express อ่าน JSON ได้ (เวลาเราส่ง Data มาจากหน้าบ้าน)
app.use(express.json());

// --- สร้าง Route สำหรับทดสอบ ---

// 1. หน้าแรกสำหรับเช็คสถานะ
app.get('/', (req, res) => {
    const start = Date.now();
    res.json({
        message: "Poop AI Express API is Live!",
        access: "Public (CORS Enabled)",
        timestamp: new Date().toISOString(),
        latency_test: `${Date.now() - start}ms`
    });
});

// 2. Endpoint สำหรับเทสความเร็วตอนส่งข้อมูล
app.post('/test-speed', (req, res) => {
    res.json({ 
        status: "received", 
        server_time: new Date().toLocaleTimeString(),
        your_data: req.body 
    });
});

// สั่งให้ Server เริ่มทำงาน
app.listen(PORT, '0.0.0.0', () => {
    console.log(`Server is running on http://0.0.0.0:${PORT}`);
    console.log(`CORS is enabled for all origins.`);
});