mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
feat :
- Added tunnel - Removed cloud feature
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { cleanupProviderConnections, getSettings } from "@/lib/localDb";
|
||||
import { enableTunnel } from "@/lib/tunnel/tunnelManager";
|
||||
import { killCloudflared, isCloudflaredRunning, ensureCloudflared } from "@/lib/tunnel/cloudflared";
|
||||
|
||||
/**
|
||||
* Initialize app on startup
|
||||
* - Cleanup stale data
|
||||
* - Auto-reconnect tunnel if previously enabled
|
||||
* - Register shutdown handler to kill cloudflared
|
||||
*/
|
||||
export async function initializeApp() {
|
||||
try {
|
||||
await cleanupProviderConnections();
|
||||
|
||||
// Auto-reconnect tunnel if it was enabled before restart
|
||||
const settings = await getSettings();
|
||||
if (settings.tunnelEnabled && !isCloudflaredRunning()) {
|
||||
console.log("[InitApp] Tunnel was enabled, auto-reconnecting...");
|
||||
try {
|
||||
await enableTunnel();
|
||||
console.log("[InitApp] Tunnel reconnected");
|
||||
} catch (error) {
|
||||
console.log("[InitApp] Tunnel reconnect failed:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Kill cloudflared on process exit
|
||||
const cleanup = () => {
|
||||
killCloudflared();
|
||||
process.exit();
|
||||
};
|
||||
process.on("SIGINT", cleanup);
|
||||
process.on("SIGTERM", cleanup);
|
||||
|
||||
// Pre-download cloudflared binary in background
|
||||
ensureCloudflared().catch(() => {});
|
||||
} catch (error) {
|
||||
console.error("[InitApp] Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export default initializeApp;
|
||||
Reference in New Issue
Block a user