streamai / proxy.js
unknown
hi
ead0236
const http = require('http');
// Configuration
const TARGET_PORT = 11470;
const LISTEN_PORT = 7860;
console.log('===== Simple Stremio Proxy Starting =====');
// Create a proxy server with minimal complexity
const server = http.createServer((req, res) => {
const timestamp = new Date().toISOString();
// Special route for health checks
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}`);
// Forward request to Stremio server
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);
});
// Handle errors
proxyReq.on('error', (e) => {
console.error(`${timestamp}: Proxy error: ${e.message}`);
res.writeHead(503);
res.end('Stremio server is not responding');
});
// Pipe original request to proxy request
req.pipe(proxyReq);
});
// Handle server errors
server.on('error', (e) => {
console.error(`Server error: ${e.message}`);
});
// Start the server
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 =====');
});