File size: 989 Bytes
af0713d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}`);
});