feat(hooks): allow gmail tailscale target URLs

This commit is contained in:
Peter Steinberger
2026-01-10 19:19:30 +01:00
parent 0335bccd91
commit 1fe9f648b1
12 changed files with 89 additions and 7 deletions

View File

@@ -60,6 +60,7 @@ export type GmailSetupOptions = {
renewEveryMinutes?: number;
tailscale?: "off" | "serve" | "funnel";
tailscalePath?: string;
tailscaleTarget?: string;
pushEndpoint?: string;
json?: boolean;
};
@@ -80,6 +81,7 @@ export type GmailRunOptions = {
renewEveryMinutes?: number;
tailscale?: "off" | "serve" | "funnel";
tailscalePath?: string;
tailscaleTarget?: string;
};
const DEFAULT_GMAIL_TOPIC_IAM_MEMBER =
@@ -134,11 +136,18 @@ export async function runGmailSetup(opts: GmailSetupOptions) {
const serveBind = opts.bind ?? DEFAULT_GMAIL_SERVE_BIND;
const servePort = opts.port ?? DEFAULT_GMAIL_SERVE_PORT;
const configuredServePath = opts.path ?? baseConfig.hooks?.gmail?.serve?.path;
const configuredTailscaleTarget =
opts.tailscaleTarget ?? baseConfig.hooks?.gmail?.tailscale?.target;
const normalizedServePath =
typeof configuredServePath === "string" &&
configuredServePath.trim().length > 0
? normalizeServePath(configuredServePath)
: DEFAULT_GMAIL_SERVE_PATH;
const normalizedTailscaleTarget =
typeof configuredTailscaleTarget === "string" &&
configuredTailscaleTarget.trim().length > 0
? configuredTailscaleTarget.trim()
: undefined;
const includeBody = opts.includeBody ?? true;
const maxBytes = opts.maxBytes ?? DEFAULT_GMAIL_MAX_BYTES;
@@ -149,7 +158,9 @@ export async function runGmailSetup(opts: GmailSetupOptions) {
// Tailscale strips the path before proxying; keep a public path while gog
// listens on "/" whenever Tailscale is enabled.
const servePath = normalizeServePath(
tailscaleMode !== "off" ? "/" : normalizedServePath,
tailscaleMode !== "off" && !normalizedTailscaleTarget
? "/"
: normalizedServePath,
);
const tailscalePath = normalizeServePath(
opts.tailscalePath ??
@@ -189,6 +200,7 @@ export async function runGmailSetup(opts: GmailSetupOptions) {
mode: tailscaleMode,
path: tailscalePath,
port: servePort,
target: normalizedTailscaleTarget,
token: pushToken,
});
@@ -236,6 +248,7 @@ export async function runGmailSetup(opts: GmailSetupOptions) {
...baseConfig.hooks?.gmail?.tailscale,
mode: tailscaleMode,
path: tailscalePath,
target: normalizedTailscaleTarget,
},
},
},
@@ -299,6 +312,7 @@ export async function runGmailService(opts: GmailRunOptions) {
renewEveryMinutes: opts.renewEveryMinutes,
tailscaleMode: opts.tailscale,
tailscalePath: opts.tailscalePath,
tailscaleTarget: opts.tailscaleTarget,
};
const resolved = resolveGmailHookRuntimeConfig(config, overrides);
@@ -314,6 +328,7 @@ export async function runGmailService(opts: GmailRunOptions) {
mode: runtimeConfig.tailscale.mode,
path: runtimeConfig.tailscale.path,
port: runtimeConfig.serve.port,
target: runtimeConfig.tailscale.target,
});
}