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:
- 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
```

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://");
}
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(

View file

@ -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}`,
];

View file

@ -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}`,