| | const http = require('http'); |
| |
|
| | |
| | const TARGET_PORT = 11470; |
| | const LISTEN_PORT = 7860; |
| |
|
| | console.log('===== Simple Stremio Proxy Starting ====='); |
| |
|
| | |
| | const server = http.createServer((req, res) => { |
| | const timestamp = new Date().toISOString(); |
| | |
| | |
| | if (req.url === '/health' || req.url === '/') { |
| | console.log(`${timestamp}: Health check request received`); |
| | res.writeHead(200, { 'Content-Type': 'application/json' }); |
| | res.end(JSON.stringify({ |
| | status: 'up', |
| | message: 'Stremio proxy is running', |
| | timestamp: timestamp |
| | })); |
| | return; |
| | } |
| |
|
| | console.log(`${timestamp}: Proxying request to: ${req.url}`); |
| | |
| | |
| | const proxyReq = http.request({ |
| | hostname: 'localhost', |
| | port: TARGET_PORT, |
| | path: req.url, |
| | method: req.method, |
| | headers: req.headers |
| | }, (proxyRes) => { |
| | res.writeHead(proxyRes.statusCode, proxyRes.headers); |
| | proxyRes.pipe(res); |
| | }); |
| | |
| | |
| | proxyReq.on('error', (e) => { |
| | console.error(`${timestamp}: Proxy error: ${e.message}`); |
| | res.writeHead(503); |
| | res.end('Stremio server is not responding'); |
| | }); |
| | |
| | |
| | req.pipe(proxyReq); |
| | }); |
| |
|
| | |
| | server.on('error', (e) => { |
| | console.error(`Server error: ${e.message}`); |
| | }); |
| |
|
| | |
| | server.listen(LISTEN_PORT, () => { |
| | console.log(`Proxy server listening on port ${LISTEN_PORT}`); |
| | console.log(`Forwarding requests to port ${TARGET_PORT}`); |
| | console.log('===== Proxy Server Started ====='); |
| | }); |