File size: 1,642 Bytes
ead0236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 =====');
});