stream / stremio-minimal.js
y59's picture
Upload stremio-minimal.js
6552625 verified
/**
* Minimal Stremio Server
*
* This is a bare-bones implementation that attempts to start the Stremio server.
*/
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
console.log('===== Minimal Stremio Server Starter =====');
// Search for the server.js file
const searchPaths = [
'/srv/stremio-server',
'/app',
'/usr/lib/node_modules/stremio-server',
'/opt/stremio'
];
// Try to find stremio-server module
const findServerJs = () => {
for (const basePath of searchPaths) {
const serverPath = path.join(basePath, 'server.js');
try {
if (fs.existsSync(serverPath)) {
console.log(`Found server.js at: ${serverPath}`);
return serverPath;
}
} catch (e) {
console.log(`Error checking ${serverPath}: ${e.message}`);
}
}
// Try to find it using find command
try {
const { execSync } = require('child_process');
const result = execSync('find / -name server.js 2>/dev/null | grep stremio').toString().trim();
if (result) {
console.log(`Found server.js using find: ${result}`);
return result.split('\n')[0];
}
} catch (e) {
console.log(`Error using find: ${e.message}`);
}
return null;
};
const serverJsPath = findServerJs();
if (!serverJsPath) {
console.error('Could not find server.js');
process.exit(1);
}
// Start the Stremio server
console.log(`Starting Stremio server with Node...`);
const nodeArgs = [serverJsPath];
const stremioServer = spawn('node', nodeArgs, {
stdio: 'inherit',
env: {
...process.env,
NO_CORS: '1',
CASTING_DISABLED: '1',
STREMIO_LOGGING: '1',
APP_PATH: process.env.APP_PATH || '/tmp/.stremio-server'
}
});
stremioServer.on('close', (code) => {
console.log(`Stremio server exited with code ${code}`);
process.exit(code);
});
process.on('SIGINT', () => {
console.log('Received SIGINT, shutting down...');
stremioServer.kill('SIGINT');
});
process.on('SIGTERM', () => {
console.log('Received SIGTERM, shutting down...');
stremioServer.kill('SIGTERM');
});