refactor(cli): specify that forgejo base url should point to internal

forgejo address in container
This commit is contained in:
ZTatman 2026-04-16 13:02:01 -04:00
parent 4ceb1ff223
commit b87c4554fb
5 changed files with 30 additions and 10 deletions

View file

@ -54,7 +54,7 @@ myst config init
Prompts for: 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) - Forgejo PAT (with `read:user` and `read:repository` scopes)
### 2. Deploy with Docker Compose ### 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: Create a `.env` file with:
```env ```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 FORGEJO_PAT=forgejo_pat_xxxxxxxxxxxx
``` ```

View file

@ -1,3 +1,3 @@
{ {
"forgejoBaseUrl": "https://git.example.com" "forgejoBaseUrl": "http://forgejo:3000"
} }

View file

@ -16,7 +16,20 @@ function normalizeHttpUrl(value: string): string {
throw new Error("URLs must use http:// or https://"); 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( function validateHttpUrlOrHost(
@ -118,8 +131,8 @@ async function init(opts: { output?: string }) {
{ {
forgejoBaseUrl: () => forgejoBaseUrl: () =>
p.text({ p.text({
message: "Domain name or URL for your existing Forgejo instance?", message: "Forgejo API URL (how Myst reaches Forgejo, not your browser URL)?",
placeholder: "git.example.com", placeholder: "http://forgejo:3000",
validate: (v) => validateHttpUrlOrHost(v, "Forgejo base URL"), validate: (v) => validateHttpUrlOrHost(v, "Forgejo base URL"),
}), }),
forgejoPat: () => forgejoPat: () =>
@ -170,9 +183,11 @@ async function init(opts: { output?: string }) {
s.stop(c.yellow(`.env created at ${envPath}`)); s.stop(c.yellow(`.env created at ${envPath}`));
p.note( 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"), ].join("\n"),
); );
p.log.success( p.log.success(

View file

@ -43,7 +43,9 @@ export function parseEnvFile(
export function generateEnvFile(options: MystEnvironmentVariables): string { export function generateEnvFile(options: MystEnvironmentVariables): string {
const lines = [ 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_BASE_URL=${options.forgejoBaseUrl}`,
`FORGEJO_PAT=${options.forgejoPat}`, `FORGEJO_PAT=${options.forgejoPat}`,
]; ];

View file

@ -78,7 +78,7 @@ export async function checkRepoAccess(
Authorization: `token ${pat}`, Authorization: `token ${pat}`,
}, },
}), }),
fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, { fetchWithTimeout(`${baseUrl}/api/v1/user/repos?limit=1`, {
method: "GET", method: "GET",
headers: { headers: {
Authorization: `token ${pat}`, Authorization: `token ${pat}`,