Add direct gateway forwarding when VPN is off
All checks were successful
Build and Deploy Gateway / build-and-push (push) Successful in 14s
Build and Deploy Gateway / deploy (push) Successful in 1s

This commit is contained in:
2026-07-11 11:37:08 +03:00
parent 9d4f312595
commit 41922ad30b
14 changed files with 264 additions and 46 deletions

View File

@@ -3,6 +3,7 @@ import http from 'node:http';
import path from 'node:path';
import { spawn, spawnSync } from 'node:child_process';
import { settings } from './config.js';
import { setGatewayInterception } from './gatewayRouting.js';
import { tcpPing } from './ping.js';
import { buildSharedProxyInfo } from './sharedProxy.js';
import {
@@ -90,6 +91,9 @@ function checkSingboxConfig() {
function stopSingbox() {
return new Promise((resolve) => {
if (settings.appMode === 'gateway') {
setGatewayInterception(false, settings.tproxyChain);
}
if (!singboxProcess) {
singboxStartedAt = null;
return resolve();
@@ -112,7 +116,12 @@ function stopSingbox() {
}
async function startSingbox() {
if (!fs.existsSync(settings.configPath)) return false;
if (!fs.existsSync(settings.configPath)) {
if (settings.appMode === 'gateway') {
setGatewayInterception(false, settings.tproxyChain);
}
return false;
}
checkSingboxConfig();
await stopSingbox();
@@ -121,10 +130,23 @@ async function startSingbox() {
});
singboxProcess = child;
singboxStartedAt = new Date().toISOString();
try {
if (settings.appMode === 'gateway') {
setGatewayInterception(true, settings.tproxyChain);
}
} catch (error) {
child.kill('SIGTERM');
singboxProcess = null;
singboxStartedAt = null;
throw error;
}
child.once('exit', () => {
if (singboxProcess === child) {
singboxProcess = null;
singboxStartedAt = null;
if (settings.appMode === 'gateway') {
setGatewayInterception(false, settings.tproxyChain);
}
}
});
return true;