Files
LunaTV/start.js
2025-07-05 18:49:35 +08:00

29 lines
801 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/* eslint-disable no-console,@typescript-eslint/no-var-requires */
const http = require('http');
// 直接在当前进程中启动 standalone Server`server.js`
require('./server.js');
// 每 1 秒轮询一次,直到请求成功
const TARGET_URL = `http://${process.env.HOSTNAME || 'localhost'}:${
process.env.PORT || 3000
}/login`;
const intervalId = setInterval(() => {
console.log(`Fetching ${TARGET_URL} ...`);
const req = http.get(TARGET_URL, (res) => {
// 当返回 2xx 状态码时认为成功,然后停止轮询
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
console.log('Server is up, stop polling.');
clearInterval(intervalId);
}
});
req.setTimeout(2000, () => {
req.destroy();
});
}, 1000);