FreeLLMAPI / server /dist /index.js
Nryn215's picture
Upload folder using huggingface_hub
077865a verified
Raw
History Blame Contribute Delete
2.08 kB
import './env.js';
import { createApp } from './app.js';
import { initDb } from './db/index.js';
import { startHealthChecker } from './services/health.js';
const PORT = process.env.PORT ?? 3001;
// Dual-stack ('::') by default so the dashboard is reachable over both IPv4
// and IPv6 (e.g. IPv6-enabled Docker networks β€” #180). Hosts with IPv6
// disabled fall back to IPv4-only below; HOST overrides the default outright.
const HOST = process.env.HOST ?? '::';
async function main() {
initDb();
const app = createApp();
const onReady = (host) => () => {
const display = host.includes(':') ? `[${host}]` : host;
console.log(`Server running on http://${display}:${PORT}`);
console.log(`Proxy endpoint: http://${display}:${PORT}/v1/chat/completions`);
startHealthChecker();
};
const server = app.listen(Number(PORT), HOST, onReady(HOST));
server.on('error', (err) => {
// The default '::' bind fails where IPv6 is disabled (kernel
// ipv6.disable=1 and the like) β€” retry IPv4-only rather than dying.
// Anything else (EADDRINUSE, an explicit HOST that can't bind) keeps the
// fail-fast posture documented in main().catch below.
if (!process.env.HOST && (err.code === 'EAFNOSUPPORT' || err.code === 'EADDRNOTAVAIL')) {
console.warn('[server] IPv6 unavailable on this host β€” falling back to 0.0.0.0 (IPv4-only)');
app.listen(Number(PORT), '0.0.0.0', onReady('0.0.0.0'));
return;
}
console.error('\n[server] Failed to start:\n ' + (err?.message ?? err) + '\n');
process.exit(1);
});
}
main().catch((err) => {
// A boot failure (e.g. a missing production ENCRYPTION_KEY) must exit
// non-zero rather than leaving a half-initialized process that never starts
// listening β€” that silent state is what surfaces in the client as
// "Can't reach the server".
console.error('\n[server] Failed to start:\n ' + (err?.message ?? err) + '\n');
process.exit(1);
});
//# sourceMappingURL=index.js.map