Refactor VPN proxy client implementation
Build and Deploy Gateway / build-and-push (push) Failing after 2s
Build and Deploy Gateway / deploy (push) Has been skipped

This commit is contained in:
2026-08-09 00:41:52 +03:00
parent 32be4380a3
commit 34d8b681ad
190 changed files with 20064 additions and 9761 deletions
@@ -0,0 +1,32 @@
import type { IncomingMessage, ServerResponse } from 'node:http';
import type { GatewayAutoService } from '../../features/routing/index.js';
import { HarborError } from '../../../shared/errors.js';
import { sendJson } from '../response.js';
interface GatewayAutoRouteDependencies {
appMode: string;
gatewayAuto: Pick<GatewayAutoService, 'setEnabled'>;
readBody(req: IncomingMessage): Promise<Record<string, unknown>>;
withOperation<T>(kind: string, operation: () => Promise<T>): Promise<T>;
readStatePayload(): Promise<Record<string, unknown> & { gatewayAuto?: unknown }>;
}
export function createGatewayAutoRoute(dependencies: GatewayAutoRouteDependencies) {
return {
async handle(req: IncomingMessage, res: ServerResponse) {
if (req.method !== 'POST' || req.url !== '/api/gateway-auto') return false;
if (dependencies.appMode !== 'client') throw new HarborError('REQUEST_INVALID');
const { enabled } = await dependencies.readBody(req);
if (typeof enabled !== 'boolean') throw new HarborError('REQUEST_INVALID');
await dependencies.withOperation(
'gateway-auto',
() => dependencies.gatewayAuto.setEnabled(enabled),
);
const state = await dependencies.readStatePayload();
sendJson(res, 200, { success: true, gatewayAuto: state.gatewayAuto, state });
return true;
},
};
}