Update proxy.js
Browse files
proxy.js
CHANGED
|
@@ -1,97 +1,60 @@
|
|
| 1 |
const http = require('http');
|
| 2 |
|
|
|
|
| 3 |
const TARGET_PORT = 11470;
|
| 4 |
const LISTEN_PORT = 7860;
|
| 5 |
|
| 6 |
-
console.log(
|
| 7 |
-
console.log(`${new Date().toISOString()}: Proxy will forward from port ${LISTEN_PORT} to ${TARGET_PORT}`);
|
| 8 |
|
| 9 |
-
//
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
});
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
console.log(`${new Date().toISOString()}: Stremio server check failed: ${err.message}`);
|
| 25 |
-
resolve(false);
|
| 26 |
-
});
|
| 27 |
-
|
| 28 |
-
req.on('timeout', () => {
|
| 29 |
-
console.log(`${new Date().toISOString()}: Stremio server check timed out`);
|
| 30 |
-
req.destroy();
|
| 31 |
-
resolve(false);
|
| 32 |
-
});
|
| 33 |
-
|
| 34 |
-
req.end();
|
| 35 |
-
});
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
// Create a proxy server
|
| 39 |
-
const proxy = http.createServer((clientReq, clientRes) => {
|
| 40 |
-
const clientIP = clientReq.headers['x-forwarded-for'] || clientReq.socket.remoteAddress;
|
| 41 |
-
console.log(`${new Date().toISOString()}: Proxying request from ${clientIP} to: ${clientReq.url}`);
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
hostname: 'localhost',
|
| 46 |
port: TARGET_PORT,
|
| 47 |
-
path:
|
| 48 |
-
method:
|
| 49 |
-
headers:
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
const proxyReq = http.request(options, (proxyRes) => {
|
| 54 |
-
console.log(`${new Date().toISOString()}: Got response from Stremio server: ${proxyRes.statusCode}`);
|
| 55 |
-
clientRes.writeHead(proxyRes.statusCode, proxyRes.headers);
|
| 56 |
-
proxyRes.pipe(clientRes, { end: true });
|
| 57 |
});
|
| 58 |
-
|
| 59 |
// Handle errors
|
| 60 |
-
proxyReq.on('error', (
|
| 61 |
-
console.error(`${
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
});
|
| 65 |
-
|
| 66 |
-
// Add request timeout
|
| 67 |
-
proxyReq.on('timeout', () => {
|
| 68 |
-
console.error(`${new Date().toISOString()}: Request to Stremio server timed out`);
|
| 69 |
-
proxyReq.destroy();
|
| 70 |
});
|
| 71 |
|
| 72 |
-
// Pipe
|
| 73 |
-
|
| 74 |
});
|
| 75 |
|
| 76 |
-
//
|
| 77 |
-
|
| 78 |
-
console.error(`
|
| 79 |
});
|
| 80 |
|
| 81 |
-
// Start
|
| 82 |
-
(
|
| 83 |
-
console.log(`
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
console.log(`${new Date().toISOString()}: Stremio server is responding, starting proxy`);
|
| 88 |
-
} else {
|
| 89 |
-
console.log(`${new Date().toISOString()}: Stremio server is not responding, but starting proxy anyway`);
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
proxy.listen(LISTEN_PORT, () => {
|
| 93 |
-
console.log(`${new Date().toISOString()}: Proxy server running on port ${LISTEN_PORT}`);
|
| 94 |
-
console.log(`${new Date().toISOString()}: Forwarding to Stremio server on port ${TARGET_PORT}`);
|
| 95 |
-
console.log(`===== Stremio Proxy Started Successfully =====`);
|
| 96 |
-
});
|
| 97 |
-
})();
|
|
|
|
| 1 |
const http = require('http');
|
| 2 |
|
| 3 |
+
// Configuration
|
| 4 |
const TARGET_PORT = 11470;
|
| 5 |
const LISTEN_PORT = 7860;
|
| 6 |
|
| 7 |
+
console.log('===== Simple Stremio Proxy Starting =====');
|
|
|
|
| 8 |
|
| 9 |
+
// Create a proxy server with minimal complexity
|
| 10 |
+
const server = http.createServer((req, res) => {
|
| 11 |
+
const timestamp = new Date().toISOString();
|
| 12 |
+
|
| 13 |
+
// Special route for health checks
|
| 14 |
+
if (req.url === '/health' || req.url === '/') {
|
| 15 |
+
console.log(`${timestamp}: Health check request received`);
|
| 16 |
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 17 |
+
res.end(JSON.stringify({
|
| 18 |
+
status: 'up',
|
| 19 |
+
message: 'Stremio proxy is running',
|
| 20 |
+
timestamp: timestamp
|
| 21 |
+
}));
|
| 22 |
+
return;
|
| 23 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
console.log(`${timestamp}: Proxying request to: ${req.url}`);
|
| 26 |
+
|
| 27 |
+
// Forward request to Stremio server
|
| 28 |
+
const proxyReq = http.request({
|
| 29 |
hostname: 'localhost',
|
| 30 |
port: TARGET_PORT,
|
| 31 |
+
path: req.url,
|
| 32 |
+
method: req.method,
|
| 33 |
+
headers: req.headers
|
| 34 |
+
}, (proxyRes) => {
|
| 35 |
+
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
| 36 |
+
proxyRes.pipe(res);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
});
|
| 38 |
+
|
| 39 |
// Handle errors
|
| 40 |
+
proxyReq.on('error', (e) => {
|
| 41 |
+
console.error(`${timestamp}: Proxy error: ${e.message}`);
|
| 42 |
+
res.writeHead(503);
|
| 43 |
+
res.end('Stremio server is not responding');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
});
|
| 45 |
|
| 46 |
+
// Pipe original request to proxy request
|
| 47 |
+
req.pipe(proxyReq);
|
| 48 |
});
|
| 49 |
|
| 50 |
+
// Handle server errors
|
| 51 |
+
server.on('error', (e) => {
|
| 52 |
+
console.error(`Server error: ${e.message}`);
|
| 53 |
});
|
| 54 |
|
| 55 |
+
// Start the server
|
| 56 |
+
server.listen(LISTEN_PORT, () => {
|
| 57 |
+
console.log(`Proxy server listening on port ${LISTEN_PORT}`);
|
| 58 |
+
console.log(`Forwarding requests to port ${TARGET_PORT}`);
|
| 59 |
+
console.log('===== Proxy Server Started =====');
|
| 60 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|