const express = require('express'); const { createProxyMiddleware } = require('http-proxy-middleware'); const cors = require('cors'); const app = express(); const PORT = process.env.PORT || 7860; app.use(cors({ origin: '*', credentials: true, methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'] })); const proxyOptions = { target: 'https://anyrouter.top', changeOrigin: true, secure: true, followRedirects: true, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' }, onProxyReq: (proxyReq, req, res) => { console.log(`Proxying: ${req.method} ${req.url} -> https://anyrouter.top${req.url}`); }, onError: (err, req, res) => { console.error('Proxy Error:', err.message); res.status(500).json({ error: 'Proxy request failed', message: err.message }); } }; app.get('/health', (req, res) => { res.status(200).json({ status: 'healthy', timestamp: new Date().toISOString() }); }); app.use('/', createProxyMiddleware(proxyOptions)); app.listen(PORT, '0.0.0.0', () => { console.log(`Proxy server running on port ${PORT}`); console.log(`Proxying requests to: https://anyrouter.top`); console.log(`Access locally at: http://localhost:${PORT}`); });