Spaces:
Sleeping
Sleeping
| const http = require('http'); | |
| const https = require('https'); | |
| const url = require('url'); | |
| const PORT = 3002; | |
| const BINANCE_BASE = 'https://api.binance.com'; | |
| const server = http.createServer((req, res) => { | |
| // CORS headers | |
| res.setHeader('Access-Control-Allow-Origin', '*'); | |
| res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); | |
| res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); | |
| if (req.method === 'OPTIONS') { res.writeHead(200); res.end(); return; } | |
| if (!req.url.startsWith('/api/')) { res.writeHead(404); res.end('Not found'); return; } | |
| const targetUrl = BINANCE_BASE + req.url.replace('/api/binance', '/api'); | |
| https.get(targetUrl, (proxyRes) => { | |
| res.writeHead(proxyRes.statusCode, proxyRes.headers); | |
| proxyRes.pipe(res); | |
| }).on('error', (err) => { | |
| res.writeHead(500); | |
| res.end('Proxy error: ' + err.message); | |
| }); | |
| }); | |
| server.listen(PORT, '0.0.0.0', () => { | |
| console.log(`Binance proxy running on port ${PORT}`); | |
| }); | |