diff --git a/README.md b/README.md index 234bc4b..1e1accb 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ myst config init Prompts for: -- Forgejo base URL (`git.example.com`) +- Forgejo API URL — internal address when co-located (`http://forgejo:3000`) or public URL for cross-host (`https://git.example.com`) - Forgejo PAT (with `read:user` and `read:repository` scopes) ### 2. Deploy with Docker Compose @@ -82,7 +82,10 @@ Myst should not assume a VPS-only environment. The requirement is an existing Fo Create a `.env` file with: ```env -FORGEJO_BASE_URL=https://git.example.com +# Same-host (Docker network or localhost): +FORGEJO_BASE_URL=http://forgejo:3000 +# Cross-host alternative: +# FORGEJO_BASE_URL=https://git.example.com FORGEJO_PAT=forgejo_pat_xxxxxxxxxxxx ``` diff --git a/packages/cli/examples/myst.config.example.json b/packages/cli/examples/myst.config.example.json index 151e81f..d534c5e 100644 --- a/packages/cli/examples/myst.config.example.json +++ b/packages/cli/examples/myst.config.example.json @@ -1,3 +1,3 @@ { - "forgejoBaseUrl": "https://git.example.com" + "forgejoBaseUrl": "http://forgejo:3000" } diff --git a/packages/cli/src/commands/config/init.ts b/packages/cli/src/commands/config/init.ts index 7b4bf03..16e05c4 100644 --- a/packages/cli/src/commands/config/init.ts +++ b/packages/cli/src/commands/config/init.ts @@ -16,7 +16,20 @@ function normalizeHttpUrl(value: string): string { throw new Error("URLs must use http:// or https://"); } - return hasProtocol ? trimmed : `https://${trimmed}`; + if (hasProtocol) return trimmed; + + // Infer scheme from the host shape: + // - localhost, IP literals, or single-label hosts (Docker service names + // like `forgejo`) default to http:// since they're typically internal. + // - Anything that looks like a public DNS name (contains a dot) defaults + // to https:// to preserve the existing behavior for `git.example.com`. + const host = trimmed.split("/")[0]?.split(":")[0] ?? ""; + const isInternalHost = + host === "localhost" || + /^\d{1,3}(\.\d{1,3}){3}$/.test(host) || + !host.includes("."); + + return `${isInternalHost ? "http" : "https"}://${trimmed}`; } function validateHttpUrlOrHost( @@ -118,8 +131,8 @@ async function init(opts: { output?: string }) { { forgejoBaseUrl: () => p.text({ - message: "Domain name or URL for your existing Forgejo instance?", - placeholder: "git.example.com", + message: "Forgejo API URL (how Myst reaches Forgejo, not your browser URL)?", + placeholder: "http://forgejo:3000", validate: (v) => validateHttpUrlOrHost(v, "Forgejo base URL"), }), forgejoPat: () => @@ -170,9 +183,11 @@ async function init(opts: { output?: string }) { s.stop(c.yellow(`.env created at ${envPath}`)); p.note( [ - `${c.bold("Forgejo base URL:")} ${c.cyan(forgejoBaseUrl)}`, + `${c.bold("Forgejo API URL:")} ${c.cyan(forgejoBaseUrl)}`, "", - `Configure your public and admin URLs using your reverse proxy (Caddy, Nginx, etc.).`, + `Myst will use this URL to call Forgejo's API.`, + `- Same host / Docker network: http://forgejo:3000 or http://localhost:3000`, + `- Cross-host deployment: https://git.example.com`, ].join("\n"), ); p.log.success( diff --git a/packages/cli/src/utils/config.ts b/packages/cli/src/utils/config.ts index 67e3a43..b9a11ef 100644 --- a/packages/cli/src/utils/config.ts +++ b/packages/cli/src/utils/config.ts @@ -43,7 +43,9 @@ export function parseEnvFile( export function generateEnvFile(options: MystEnvironmentVariables): string { const lines = [ - `# Forgejo instance (used for API access).`, + `# Forgejo API endpoint that Myst calls.`, + `# Same-host / Docker: http://forgejo:3000 or http://localhost:3000`, + `# Cross-host: https://git.example.com`, `FORGEJO_BASE_URL=${options.forgejoBaseUrl}`, `FORGEJO_PAT=${options.forgejoPat}`, ]; diff --git a/packages/cli/src/utils/forgejo-checks.ts b/packages/cli/src/utils/forgejo-checks.ts index c6fac18..95cca86 100644 --- a/packages/cli/src/utils/forgejo-checks.ts +++ b/packages/cli/src/utils/forgejo-checks.ts @@ -78,7 +78,7 @@ export async function checkRepoAccess( Authorization: `token ${pat}`, }, }), - fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, { + fetchWithTimeout(`${baseUrl}/api/v1/user/repos?limit=1`, { method: "GET", headers: { Authorization: `token ${pat}`,