diff --git a/src/App.tsx b/src/App.tsx index fdfb0449..d4e4a1a2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -132,6 +132,7 @@ const defaultConfig: AppConfig = { ], esmUrl: "https://esm.sh", corsProxy: "https://proxy.shakespeare.diy/?url={href}", + gitProxyOrigins: ["https://github.com", "https://gitlab.com"], faviconUrl: "https://favicon.shakespeare.diy/?url={href}", ngitWebUrl: "https://nostrhub.io/{naddr}", previewDomain: "local-shakespeare.dev", diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index 28a580a3..1b457b69 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -45,6 +45,7 @@ const AppConfigSchema = z.object({ templates: z.array(ProjectTemplateSchema), esmUrl: z.string().url(), corsProxy: z.string().url(), + gitProxyOrigins: z.array(z.string()), faviconUrl: z.string().url(), ngitWebUrl: z.string().url(), previewDomain: z.string().min(1), diff --git a/src/components/SentryProvider.test.tsx b/src/components/SentryProvider.test.tsx index a5291130..4b600986 100644 --- a/src/components/SentryProvider.test.tsx +++ b/src/components/SentryProvider.test.tsx @@ -34,6 +34,7 @@ describe('SentryProvider', () => { templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://favicon.test/{href}', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'test.dev', @@ -75,6 +76,7 @@ describe('SentryProvider', () => { templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://favicon.test/{href}', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'test.dev', @@ -117,6 +119,7 @@ describe('SentryProvider', () => { templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://favicon.test/{href}', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'test.dev', @@ -162,6 +165,7 @@ describe('SentryProvider', () => { templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://favicon.test/{href}', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'test.dev', diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index ebc5224d..ac8b40c1 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -38,6 +38,8 @@ export interface AppConfig { esmUrl: string; /** HTTP proxy used to bypass CORS for AI and Git operations */ corsProxy: string; + /** Git origins that should use the CORS proxy (e.g., ["https://github.com", "https://gitlab.com"]) */ + gitProxyOrigins: string[]; /** Favicon URL template (e.g., "https://external-content.duckduckgo.com/ip3/{hostname}.ico") */ faviconUrl: string; /** Nostr Git web URL template (e.g., "https://nostrhub.io/{naddr}") */ diff --git a/src/contexts/GitSettingsContext.ts b/src/contexts/GitSettingsContext.ts index 92d178cb..ab446f63 100644 --- a/src/contexts/GitSettingsContext.ts +++ b/src/contexts/GitSettingsContext.ts @@ -6,7 +6,6 @@ export interface GitCredential { origin: string; // Full origin URL (e.g., "https://github.com") username: string; password: string; - proxy?: boolean; // Whether to use a proxy for this credential } export interface GitSettings { diff --git a/src/hooks/useGenerateProjectInfo.test.ts b/src/hooks/useGenerateProjectInfo.test.ts index 79075af5..098c94ae 100644 --- a/src/hooks/useGenerateProjectInfo.test.ts +++ b/src/hooks/useGenerateProjectInfo.test.ts @@ -63,6 +63,7 @@ describe('useGenerateProjectInfo', () => { templates: defaultTemplates, esmUrl: 'https://esm.sh', corsProxy: 'https://proxy.example.com/{href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'local-shakespeare.dev', @@ -224,6 +225,7 @@ describe('useGenerateProjectInfo', () => { templates: [], esmUrl: 'https://esm.sh', corsProxy: 'https://proxy.example.com/{href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'local-shakespeare.dev', diff --git a/src/hooks/useGit.test.ts b/src/hooks/useGit.test.ts index 7b6b5531..e049ac7d 100644 --- a/src/hooks/useGit.test.ts +++ b/src/hooks/useGit.test.ts @@ -40,6 +40,7 @@ function createWrapper(corsProxy: string) { templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }], esmUrl: 'https://esm.test', corsProxy, + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'local-test.dev', @@ -93,6 +94,7 @@ describe('useGit', () => { fs: mockFS, nostr: mockNostr, corsProxy: 'https://cors.isomorphic-git.org', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }], graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }], credentials: [], @@ -110,6 +112,7 @@ describe('useGit', () => { fs: mockFS, nostr: mockNostr, corsProxy: 'https://custom-cors.example.com', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }], graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }], credentials: [], @@ -127,6 +130,7 @@ describe('useGit', () => { fs: mockFS, nostr: mockNostr, corsProxy: 'https://cors.isomorphic-git.org', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }], graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }], credentials: [], diff --git a/src/hooks/useGit.ts b/src/hooks/useGit.ts index f8afdd39..591347dc 100644 --- a/src/hooks/useGit.ts +++ b/src/hooks/useGit.ts @@ -16,7 +16,7 @@ export function useGit(): { git: Git } { const { nostr } = useNostr(); const { config } = useAppContext(); const { settings } = useGitSettings(); - const { corsProxy, relayMetadata, graspMetadata } = config; + const { corsProxy, gitProxyOrigins, relayMetadata, graspMetadata } = config; const relayList = useMemo(() => { // Extract hostnames from grasp relay URLs for backwards compatibility with Git class @@ -45,12 +45,13 @@ export function useGit(): { git: Git } { fs, nostr, corsProxy, + gitProxyOrigins, relayList, graspList, credentials: settings.credentials, signer: user?.signer, }); - }, [fs, nostr, corsProxy, relayList, graspList, settings.credentials, user?.signer]); + }, [fs, nostr, corsProxy, gitProxyOrigins, relayList, graspList, settings.credentials, user?.signer]); return { git }; } \ No newline at end of file diff --git a/src/lib/SessionManager.test.ts b/src/lib/SessionManager.test.ts index eabc72b6..32c5a961 100644 --- a/src/lib/SessionManager.test.ts +++ b/src/lib/SessionManager.test.ts @@ -43,6 +43,7 @@ const testConfig: AppConfig = { templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }], esmUrl: 'https://esm.shakespeare.diy', corsProxy: 'https://proxy.shakespeare.diy/?url={href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'local-shakespeare.dev', diff --git a/src/lib/configUtils.test.ts b/src/lib/configUtils.test.ts index c45b957c..ce6c1ad0 100644 --- a/src/lib/configUtils.test.ts +++ b/src/lib/configUtils.test.ts @@ -162,7 +162,6 @@ describe('configUtils', () => { origin: 'https://github.com', username: 'user', password: 'token123', - proxy: true, }, ], }; diff --git a/src/lib/configUtils.ts b/src/lib/configUtils.ts index fba36e8b..54d419c7 100644 --- a/src/lib/configUtils.ts +++ b/src/lib/configUtils.ts @@ -64,7 +64,6 @@ const gitCredentialSchema = z.object({ origin: z.string(), username: z.string(), password: z.string(), - proxy: z.boolean().optional(), }); // Old format (map of origins to credentials) @@ -284,13 +283,6 @@ export async function readGitSettings(fs: JSRuntimeFS, configPath = '/config'): credentials = convertCredentialsToNewFormat(parsed.credentials); } - // Set default proxy settings if missing - for (const cred of credentials) { - if (!('proxy' in cred)) { - cred.proxy = ['https://github.com', 'https://gitlab.com'].includes(cred.origin); - } - } - return { ...parsed, credentials, diff --git a/src/lib/git.ts b/src/lib/git.ts index f8d9be85..11b1f98d 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -16,12 +16,13 @@ export interface GitOptions { signer?: NostrSigner; credentials?: GitCredential[]; corsProxy?: string; + gitProxyOrigins?: string[]; fetch?: typeof globalThis.fetch; } /** * Git class that wraps isomorphic-git and provides a cleaner interface. - * Instantiate with an fs implementation, optional corsProxy string, and optional corsProxyRegex. + * Instantiate with an fs implementation, optional corsProxy string, and optional gitProxyOrigins list. * All methods have the same names as isomorphic-git but don't require * passing fs, http, and corsProxy each time. */ @@ -33,6 +34,7 @@ export class Git { private systemAuthor: { name: string; email: string }; private signer?: NostrSigner; private corsProxy?: string; + private gitProxyOrigins: string[]; private credentials?: GitCredential[]; private customFetch?: typeof globalThis.fetch; @@ -40,6 +42,7 @@ export class Git { this.fs = options.fs; this.nostr = options.nostr; this.corsProxy = options.corsProxy; + this.gitProxyOrigins = options.gitProxyOrigins ?? []; this.relayList = options.relayList; this.graspList = options.graspList; this.systemAuthor = options.systemAuthor ?? { @@ -65,15 +68,22 @@ export class Git { // Get HTTP adapter for the given URL private httpForUrl(url: string | null | undefined): HttpClient { - if (url?.startsWith('nostr://')) { + if (!url || url.startsWith('nostr://')) { return new GitHttp(undefined, this.customFetch); } - if (this.credentials && url) { - const cred = findCredentialsForRepo(url, this.credentials); - if (cred && cred.proxy) { + + // Check if the URL's origin is in the proxy origins list + try { + const urlObj = new URL(url); + const origin = urlObj.origin; + + if (this.gitProxyOrigins.includes(origin)) { return new GitHttp(this.corsProxy, this.customFetch); } + } catch { + // Invalid URL, don't use proxy } + return new GitHttp(undefined, this.customFetch); } diff --git a/src/lib/system.test.ts b/src/lib/system.test.ts index f90778b9..0a651450 100644 --- a/src/lib/system.test.ts +++ b/src/lib/system.test.ts @@ -30,6 +30,7 @@ const testConfig: AppConfig = { templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }], esmUrl: 'https://esm.shakespeare.diy', corsProxy: 'https://proxy.shakespeare.diy/?url={href}', + gitProxyOrigins: ['https://github.com', 'https://gitlab.com'], faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', ngitWebUrl: 'https://nostrhub.io/{naddr}', previewDomain: 'local-shakespeare.dev', diff --git a/src/pages/GitSettings.tsx b/src/pages/GitSettings.tsx index f09d8010..9e1bb4fe 100644 --- a/src/pages/GitSettings.tsx +++ b/src/pages/GitSettings.tsx @@ -24,7 +24,6 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Badge } from '@/components/ui/badge'; -import { Checkbox } from '@/components/ui/checkbox'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Card, CardContent } from '@/components/ui/card'; import { Switch } from '@/components/ui/switch'; @@ -49,7 +48,6 @@ interface PresetProvider { origin: string; username: string; tokenURL?: string; - proxy?: boolean; } const PRESET_PROVIDERS: PresetProvider[] = [ @@ -59,7 +57,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [ origin: "https://github.com", username: "git", tokenURL: "https://github.com/settings/tokens", - proxy: true, }, { id: "gitlab", @@ -67,7 +64,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [ origin: "https://gitlab.com", username: "git", tokenURL: "https://gitlab.com/-/user_settings/personal_access_tokens", - proxy: true, }, ]; @@ -177,18 +173,6 @@ function SortableCredentialItem({ credential, onUpdate, onRemove, showDragHandle onChange={(e) => updateCredential({ password: e.target.value })} /> -
- updateCredential({ - proxy: checked === true || undefined - })} - /> - -