mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-18 05:25:49 +00:00
Server.js
Set up Express server with CORS and JSON support. Created API endpoints for account information and user actions.
This commit is contained in:
parent
258b08fff3
commit
3ace88dc12
1 changed files with 48 additions and 0 deletions
48
Server.js
Normal file
48
Server.js
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const PORT = 3000;
|
||||||
|
|
||||||
|
// อนุญาตให้หน้าเว็บอื่นดึงข้อมูลได้ และให้รองรับการรับ-ส่งข้อมูลแบบ JSON
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
// ------------------------------------------------
|
||||||
|
// สร้าง API Endpoint (ช่องทางรับออเดอร์)
|
||||||
|
// ------------------------------------------------
|
||||||
|
|
||||||
|
// 1. API ดึงข้อมูลบัญชี (สมมติว่าเป็นบัญชี vpn ของลูกค้า)
|
||||||
|
app.get('/api/account', (req, res) => {
|
||||||
|
// ข้อมูลที่เราจะส่งกลับไปเป็น JSON
|
||||||
|
const data = {
|
||||||
|
status: "success",
|
||||||
|
accountName: "2zong2",
|
||||||
|
protocol: "VLESS",
|
||||||
|
expireDays: 999,
|
||||||
|
usedGB: 21.39
|
||||||
|
};
|
||||||
|
|
||||||
|
// สั่งให้ส่ง data กลับไป
|
||||||
|
res.json(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. API รับคำสั่ง (เช่น กดปุ่มรีเซ็ตจากหน้าเว็บ)
|
||||||
|
app.post('/api/action', (req, res) => {
|
||||||
|
// อ่านข้อมูล JSON ที่หน้าเว็บส่งมา
|
||||||
|
const userAction = req.body.action;
|
||||||
|
|
||||||
|
console.log("ได้รับคำสั่งจากหน้าเว็บ:", userAction);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
status: "success",
|
||||||
|
message: `ทำคำสั่ง ${userAction} สำเร็จแล้ว!`
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ------------------------------------------------
|
||||||
|
// สั่งให้ API เริ่มทำงาน (เปิดร้านรับลูกค้า)
|
||||||
|
// ------------------------------------------------
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`🚀 API Server รันอยู่บน http://localhost:${PORT}`);
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue