const express = require("express"); const app = express(); app.use(express.json()); const PRICE_SATANG = 10; // ตัวอย่างเพื่อทดลองเท่านั้น // ระบบจริงต้องตรวจสอบ API Key จากฐานข้อมูล const apiKeys = new Map([ ["demo-key", { userId: "user-001" }] ]); const usage = new Map(); app.post("/api/quote", (req, res) => { const key = req.get("x-api-key"); const account = apiKeys.get(key); if (!account) { return res.status(401).json({ error: "Invalid API key" }); } const userId = account.userId; usage.set(userId, (usage.get(userId) || 0) + 1); res.json({ message: "Request accepted", userId, requestCount: usage.get(userId), feeSatang: PRICE_SATANG, feeBaht: PRICE_SATANG / 100, note: "Demo only; no SOL was transferred" }); }); app.listen(3000, () => { console.log("API listening on port 3000"); }); node server.js curl -X POST http://localhost:3000/api/quote \ -H "Content-Type: application/json" \ -H "x-api-key: demo-key" \ -d '{}'
Activity
mee28suteesak-crypto commentedon Oct 12, 2026
[-]npm init -y npm install express[/-][+][SPAM][/+]