feat: support configurable gateway port

This commit is contained in:
Peter Steinberger
2026-01-03 12:00:17 +01:00
parent 7199813969
commit f47c7ac369
23 changed files with 172 additions and 46 deletions

View File

@@ -5,6 +5,7 @@ import {
CONFIG_PATH_CLAWDIS,
loadConfig,
readConfigFileSnapshot,
resolveGatewayPort,
validateConfigObject,
writeConfigFile,
} from "../config/config.js";
@@ -128,7 +129,7 @@ export async function runGmailSetup(opts: GmailSetupOptions) {
const hookUrl =
opts.hookUrl ??
baseConfig.hooks?.gmail?.hookUrl ??
buildDefaultHookUrl(hooksPath);
buildDefaultHookUrl(hooksPath, resolveGatewayPort(baseConfig));
const serveBind = opts.bind ?? DEFAULT_GMAIL_SERVE_BIND;
const servePort = opts.port ?? DEFAULT_GMAIL_SERVE_PORT;

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import type { ClawdisConfig } from "../config/config.js";
import { type ClawdisConfig, DEFAULT_GATEWAY_PORT } from "../config/config.js";
import {
buildDefaultHookUrl,
buildTopicPath,
@@ -20,8 +20,8 @@ const baseConfig = {
describe("gmail hook config", () => {
it("builds default hook url", () => {
expect(buildDefaultHookUrl("/hooks")).toBe(
"http://127.0.0.1:18789/hooks/gmail",
expect(buildDefaultHookUrl("/hooks", DEFAULT_GATEWAY_PORT)).toBe(
`http://127.0.0.1:${DEFAULT_GATEWAY_PORT}/hooks/gmail`,
);
});
@@ -41,7 +41,9 @@ describe("gmail hook config", () => {
expect(result.value.label).toBe("INBOX");
expect(result.value.includeBody).toBe(true);
expect(result.value.serve.port).toBe(8788);
expect(result.value.hookUrl).toBe("http://127.0.0.1:18789/hooks/gmail");
expect(result.value.hookUrl).toBe(
`http://127.0.0.1:${DEFAULT_GATEWAY_PORT}/hooks/gmail`,
);
}
});

View File

@@ -1,8 +1,10 @@
import { randomBytes } from "node:crypto";
import type {
ClawdisConfig,
import {
type ClawdisConfig,
DEFAULT_GATEWAY_PORT,
HooksGmailTailscaleMode,
resolveGatewayPort,
} from "../config/config.js";
export const DEFAULT_GMAIL_LABEL = "INBOX";
@@ -14,7 +16,6 @@ export const DEFAULT_GMAIL_SERVE_PATH = "/gmail-pubsub";
export const DEFAULT_GMAIL_MAX_BYTES = 20_000;
export const DEFAULT_GMAIL_RENEW_MINUTES = 12 * 60;
export const DEFAULT_HOOKS_PATH = "/hooks";
export const DEFAULT_HOOKS_BASE_URL = "http://127.0.0.1:18789";
export type GmailHookOverrides = {
account?: string;
@@ -87,9 +88,13 @@ export function normalizeServePath(raw?: string): string {
return withSlash.replace(/\/+$/, "");
}
export function buildDefaultHookUrl(hooksPath?: string): string {
export function buildDefaultHookUrl(
hooksPath?: string,
port: number = DEFAULT_GATEWAY_PORT,
): string {
const basePath = normalizeHooksPath(hooksPath);
return joinUrl(DEFAULT_HOOKS_BASE_URL, `${basePath}/gmail`);
const baseUrl = `http://127.0.0.1:${port}`;
return joinUrl(baseUrl, `${basePath}/gmail`);
}
export function resolveGmailHookRuntimeConfig(
@@ -122,7 +127,9 @@ export function resolveGmailHookRuntimeConfig(
}
const hookUrl =
overrides.hookUrl ?? gmail?.hookUrl ?? buildDefaultHookUrl(hooks?.path);
overrides.hookUrl ??
gmail?.hookUrl ??
buildDefaultHookUrl(hooks?.path, resolveGatewayPort(cfg));
const includeBody = overrides.includeBody ?? gmail?.includeBody ?? true;