const express = require("express"); const cors = require("cors"); const fetch = require("node-fetch"); const path = require("path"); const bodyParser = require("body-parser"); const app = express(); const PORT = process.env.PORT || 3000; app.use(cors()); app.use(express.urlencoded({ extended: true })); // FormData support app.use(express.json()); // Serve hehe.html app.get("/", (req, res) => { res.sendFile(path.join(__dirname, "hehe.html")); }); // Proxy endpoint app.post("/proxy", async (req, res) => { const targetUrl = req.body.target; if (!targetUrl) { return res.status(400).send("Missing 'target' in request body."); } // Buang 'target' dari body, sisanya dikirim const { target, ...params } = req.body; const form = new URLSearchParams(params).toString(); console.log("⏩ Sending to:", targetUrl); console.log("📦 Data:", form); try { const response = await fetch(targetUrl, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", "User-Agent": "Dart/3.3 (dart:io)", "Accept-Encoding": "gzip" }, body: form }); const contentType = response.headers.get("content-type") || "text/plain"; res.setHeader("Content-Type", contentType); const text = await response.text(); res.send(text); } catch (err) { res.status(500).json({ error: "Proxy failed", detail: err.message }); } }); app.listen(PORT, () => { console.log(`✅ Proxy running at http://localhost:${PORT}`); });