Files
rspade_system/bin/ssr-server.js
root daa9bb2fb1 Framework updates
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-12 19:09:07 +00:00

62 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* RSpade SSR Server
*
* Thin wrapper around @jqhtml/ssr server.
* Starts a long-running Node process that renders jqhtml components to HTML.
* Managed by Rsx_SSR.php — spawned on-demand, communicates via Unix socket.
*
* Usage:
* node system/bin/ssr-server.js --socket=/path/to/ssr-server.sock
*/
const path = require('path');
const { SSRServer } = require(path.join(__dirname, '..', 'node_modules', '@jqhtml', 'ssr', 'src', 'server.js'));
// Parse --socket argument
let socketPath = null;
for (let i = 2; i < process.argv.length; i++) {
if (process.argv[i].startsWith('--socket=')) {
socketPath = process.argv[i].split('=')[1];
}
}
if (!socketPath) {
socketPath = path.join(__dirname, '..', 'storage', 'rsx-tmp', 'ssr-server.sock');
}
const server = new SSRServer({
maxBundles: 10,
defaultTimeout: 30000
});
(async () => {
try {
await server.listenUnix(socketPath);
} catch (err) {
console.error('[SSR] Failed to start:', err.message);
process.exit(1);
}
})();
// Ignore SIGHUP so server survives terminal disconnect
process.on('SIGHUP', () => {});
process.on('SIGINT', async () => {
await server.stop();
process.exit(0);
});
process.on('SIGTERM', async () => {
await server.stop();
process.exit(0);
});
process.on('unhandledRejection', (err) => {
console.error('[SSR] Unhandled rejection:', err);
});
process.on('uncaughtException', (err) => {
console.error('[SSR] Uncaught exception:', err);
});