Git proxy origins are configured separately from git credentials

This commit is contained in:
Alex Gleason committed 2025-12-28 16:19:52 -06:00
1 parent f5036b8b56
commit b60d11186b
15 files changed
+35 -47

No files matched your search

+1
View File
@@ -132,6 +132,7 @@ const defaultConfig: AppConfig = {
], ],
esmUrl: "https://esm.sh", esmUrl: "https://esm.sh",
corsProxy: "https://proxy.shakespeare.diy/?url={href}", corsProxy: "https://proxy.shakespeare.diy/?url={href}",
gitProxyOrigins: ["https://github.com", "https://gitlab.com"],
faviconUrl: "https://favicon.shakespeare.diy/?url={href}", faviconUrl: "https://favicon.shakespeare.diy/?url={href}",
ngitWebUrl: "https://nostrhub.io/{naddr}", ngitWebUrl: "https://nostrhub.io/{naddr}",
previewDomain: "local-shakespeare.dev", previewDomain: "local-shakespeare.dev",
+1
View File
@@ -45,6 +45,7 @@ const AppConfigSchema = z.object({
templates: z.array(ProjectTemplateSchema), templates: z.array(ProjectTemplateSchema),
esmUrl: z.string().url(), esmUrl: z.string().url(),
corsProxy: z.string().url(), corsProxy: z.string().url(),
gitProxyOrigins: z.array(z.string()),
faviconUrl: z.string().url(), faviconUrl: z.string().url(),
ngitWebUrl: z.string().url(), ngitWebUrl: z.string().url(),
previewDomain: z.string().min(1), previewDomain: z.string().min(1),
+4
View File
@@ -34,6 +34,7 @@ describe('SentryProvider', () => {
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
esmUrl: 'https://esm.test', esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}', corsProxy: 'https://proxy.test/{href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://favicon.test/{href}', faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev', previewDomain: 'test.dev',
@@ -75,6 +76,7 @@ describe('SentryProvider', () => {
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
esmUrl: 'https://esm.test', esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}', corsProxy: 'https://proxy.test/{href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://favicon.test/{href}', faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev', previewDomain: 'test.dev',
@@ -117,6 +119,7 @@ describe('SentryProvider', () => {
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
esmUrl: 'https://esm.test', esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}', corsProxy: 'https://proxy.test/{href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://favicon.test/{href}', faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev', previewDomain: 'test.dev',
@@ -162,6 +165,7 @@ describe('SentryProvider', () => {
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
esmUrl: 'https://esm.test', esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}', corsProxy: 'https://proxy.test/{href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://favicon.test/{href}', faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev', previewDomain: 'test.dev',
+2
View File
@@ -38,6 +38,8 @@ export interface AppConfig {
esmUrl: string; esmUrl: string;
/** HTTP proxy used to bypass CORS for AI and Git operations */ /** HTTP proxy used to bypass CORS for AI and Git operations */
corsProxy: string; 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") */ /** Favicon URL template (e.g., "https://external-content.duckduckgo.com/ip3/{hostname}.ico") */
faviconUrl: string; faviconUrl: string;
/** Nostr Git web URL template (e.g., "https://nostrhub.io/{naddr}") */ /** Nostr Git web URL template (e.g., "https://nostrhub.io/{naddr}") */
-1
View File
@@ -6,7 +6,6 @@ export interface GitCredential {
origin: string; // Full origin URL (e.g., "https://github.com") origin: string; // Full origin URL (e.g., "https://github.com")
username: string; username: string;
password: string; password: string;
proxy?: boolean; // Whether to use a proxy for this credential
} }
export interface GitSettings { export interface GitSettings {
+2
View File
@@ -63,6 +63,7 @@ describe('useGenerateProjectInfo', () => {
templates: defaultTemplates, templates: defaultTemplates,
esmUrl: 'https://esm.sh', esmUrl: 'https://esm.sh',
corsProxy: 'https://proxy.example.com/{href}', corsProxy: 'https://proxy.example.com/{href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev', previewDomain: 'local-shakespeare.dev',
@@ -224,6 +225,7 @@ describe('useGenerateProjectInfo', () => {
templates: [], templates: [],
esmUrl: 'https://esm.sh', esmUrl: 'https://esm.sh',
corsProxy: 'https://proxy.example.com/{href}', corsProxy: 'https://proxy.example.com/{href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev', previewDomain: 'local-shakespeare.dev',
+4
View File
@@ -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' }], templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }],
esmUrl: 'https://esm.test', esmUrl: 'https://esm.test',
corsProxy, corsProxy,
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-test.dev', previewDomain: 'local-test.dev',
@@ -93,6 +94,7 @@ describe('useGit', () => {
fs: mockFS, fs: mockFS,
nostr: mockNostr, nostr: mockNostr,
corsProxy: 'https://cors.isomorphic-git.org', corsProxy: 'https://cors.isomorphic-git.org',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }], 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/') }], graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }],
credentials: [], credentials: [],
@@ -110,6 +112,7 @@ describe('useGit', () => {
fs: mockFS, fs: mockFS,
nostr: mockNostr, nostr: mockNostr,
corsProxy: 'https://custom-cors.example.com', corsProxy: 'https://custom-cors.example.com',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }], 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/') }], graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }],
credentials: [], credentials: [],
@@ -127,6 +130,7 @@ describe('useGit', () => {
fs: mockFS, fs: mockFS,
nostr: mockNostr, nostr: mockNostr,
corsProxy: 'https://cors.isomorphic-git.org', corsProxy: 'https://cors.isomorphic-git.org',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }], 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/') }], graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }],
credentials: [], credentials: [],
+3 -2
View File
@@ -16,7 +16,7 @@ export function useGit(): { git: Git } {
const { nostr } = useNostr(); const { nostr } = useNostr();
const { config } = useAppContext(); const { config } = useAppContext();
const { settings } = useGitSettings(); const { settings } = useGitSettings();
const { corsProxy, relayMetadata, graspMetadata } = config; const { corsProxy, gitProxyOrigins, relayMetadata, graspMetadata } = config;
const relayList = useMemo(() => { const relayList = useMemo(() => {
// Extract hostnames from grasp relay URLs for backwards compatibility with Git class // Extract hostnames from grasp relay URLs for backwards compatibility with Git class
@@ -45,12 +45,13 @@ export function useGit(): { git: Git } {
fs, fs,
nostr, nostr,
corsProxy, corsProxy,
gitProxyOrigins,
relayList, relayList,
graspList, graspList,
credentials: settings.credentials, credentials: settings.credentials,
signer: user?.signer, signer: user?.signer,
}); });
}, [fs, nostr, corsProxy, relayList, graspList, settings.credentials, user?.signer]); }, [fs, nostr, corsProxy, gitProxyOrigins, relayList, graspList, settings.credentials, user?.signer]);
return { git }; return { git };
} }
+1
View File
@@ -43,6 +43,7 @@ const testConfig: AppConfig = {
templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }], templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }],
esmUrl: 'https://esm.shakespeare.diy', esmUrl: 'https://esm.shakespeare.diy',
corsProxy: 'https://proxy.shakespeare.diy/?url={href}', corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev', previewDomain: 'local-shakespeare.dev',
-1
View File
@@ -162,7 +162,6 @@ describe('configUtils', () => {
origin: 'https://github.com', origin: 'https://github.com',
username: 'user', username: 'user',
password: 'token123', password: 'token123',
proxy: true,
}, },
], ],
}; };
-8
View File
@@ -64,7 +64,6 @@ const gitCredentialSchema = z.object({
origin: z.string(), origin: z.string(),
username: z.string(), username: z.string(),
password: z.string(), password: z.string(),
proxy: z.boolean().optional(),
}); });
// Old format (map of origins to credentials) // Old format (map of origins to credentials)
@@ -284,13 +283,6 @@ export async function readGitSettings(fs: JSRuntimeFS, configPath = '/config'):
credentials = convertCredentialsToNewFormat(parsed.credentials); 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 { return {
...parsed, ...parsed,
credentials, credentials,
+15 -5
View File
@@ -16,12 +16,13 @@ export interface GitOptions {
signer?: NostrSigner; signer?: NostrSigner;
credentials?: GitCredential[]; credentials?: GitCredential[];
corsProxy?: string; corsProxy?: string;
gitProxyOrigins?: string[];
fetch?: typeof globalThis.fetch; fetch?: typeof globalThis.fetch;
} }
/** /**
* Git class that wraps isomorphic-git and provides a cleaner interface. * 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 * All methods have the same names as isomorphic-git but don't require
* passing fs, http, and corsProxy each time. * passing fs, http, and corsProxy each time.
*/ */
@@ -33,6 +34,7 @@ export class Git {
private systemAuthor: { name: string; email: string }; private systemAuthor: { name: string; email: string };
private signer?: NostrSigner; private signer?: NostrSigner;
private corsProxy?: string; private corsProxy?: string;
private gitProxyOrigins: string[];
private credentials?: GitCredential[]; private credentials?: GitCredential[];
private customFetch?: typeof globalThis.fetch; private customFetch?: typeof globalThis.fetch;
@@ -40,6 +42,7 @@ export class Git {
this.fs = options.fs; this.fs = options.fs;
this.nostr = options.nostr; this.nostr = options.nostr;
this.corsProxy = options.corsProxy; this.corsProxy = options.corsProxy;
this.gitProxyOrigins = options.gitProxyOrigins ?? [];
this.relayList = options.relayList; this.relayList = options.relayList;
this.graspList = options.graspList; this.graspList = options.graspList;
this.systemAuthor = options.systemAuthor ?? { this.systemAuthor = options.systemAuthor ?? {
@@ -65,15 +68,22 @@ export class Git {
// Get HTTP adapter for the given URL // Get HTTP adapter for the given URL
private httpForUrl(url: string | null | undefined): HttpClient { private httpForUrl(url: string | null | undefined): HttpClient {
if (url?.startsWith('nostr://')) { if (!url || url.startsWith('nostr://')) {
return new GitHttp(undefined, this.customFetch); return new GitHttp(undefined, this.customFetch);
} }
if (this.credentials && url) {
const cred = findCredentialsForRepo(url, this.credentials); // Check if the URL's origin is in the proxy origins list
if (cred && cred.proxy) { try {
const urlObj = new URL(url);
const origin = urlObj.origin;
if (this.gitProxyOrigins.includes(origin)) {
return new GitHttp(this.corsProxy, this.customFetch); return new GitHttp(this.corsProxy, this.customFetch);
} }
} catch {
// Invalid URL, don't use proxy
} }
return new GitHttp(undefined, this.customFetch); return new GitHttp(undefined, this.customFetch);
} }
+1
View File
@@ -30,6 +30,7 @@ const testConfig: AppConfig = {
templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }], templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }],
esmUrl: 'https://esm.shakespeare.diy', esmUrl: 'https://esm.shakespeare.diy',
corsProxy: 'https://proxy.shakespeare.diy/?url={href}', corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev', previewDomain: 'local-shakespeare.dev',
-30
View File
@@ -24,7 +24,6 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';
import { Checkbox } from '@/components/ui/checkbox';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
import { Card, CardContent } from '@/components/ui/card'; import { Card, CardContent } from '@/components/ui/card';
import { Switch } from '@/components/ui/switch'; import { Switch } from '@/components/ui/switch';
@@ -49,7 +48,6 @@ interface PresetProvider {
origin: string; origin: string;
username: string; username: string;
tokenURL?: string; tokenURL?: string;
proxy?: boolean;
} }
const PRESET_PROVIDERS: PresetProvider[] = [ const PRESET_PROVIDERS: PresetProvider[] = [
@@ -59,7 +57,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
origin: "https://github.com", origin: "https://github.com",
username: "git", username: "git",
tokenURL: "https://github.com/settings/tokens", tokenURL: "https://github.com/settings/tokens",
proxy: true,
}, },
{ {
id: "gitlab", id: "gitlab",
@@ -67,7 +64,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
origin: "https://gitlab.com", origin: "https://gitlab.com",
username: "git", username: "git",
tokenURL: "https://gitlab.com/-/user_settings/personal_access_tokens", 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 })} onChange={(e) => updateCredential({ password: e.target.value })}
/> />
</div> </div>
<div className="flex items-center gap-2">
<Checkbox
id={`credential-${credential.id}-proxy`}
checked={credential.proxy || false}
onCheckedChange={(checked) => updateCredential({
proxy: checked === true || undefined
})}
/>
<Label htmlFor={`credential-${credential.id}-proxy`} className="cursor-pointer">
{t('useCorsProxy')}
</Label>
</div>
<Button <Button
variant="destructive" variant="destructive"
size="sm" size="sm"
@@ -211,7 +195,6 @@ export function GitSettings() {
const [customOrigin, setCustomOrigin] = useState(''); const [customOrigin, setCustomOrigin] = useState('');
const [customUsername, setCustomUsername] = useState(''); const [customUsername, setCustomUsername] = useState('');
const [customPassword, setCustomPassword] = useState(''); const [customPassword, setCustomPassword] = useState('');
const [customProxy, setCustomProxy] = useState(false);
const [presetTokens, setPresetTokens] = useState<Record<string, string>>({}); const [presetTokens, setPresetTokens] = useState<Record<string, string>>({});
const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({}); const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({});
@@ -233,7 +216,6 @@ export function GitSettings() {
origin: preset.origin, origin: preset.origin,
username: preset.username, username: preset.username,
password: token.trim(), password: token.trim(),
proxy: preset.proxy,
}; };
// Auto-save: Add credential immediately to persistent storage // Auto-save: Add credential immediately to persistent storage
@@ -255,7 +237,6 @@ export function GitSettings() {
origin: customOrigin.trim(), origin: customOrigin.trim(),
username: customUsername.trim(), username: customUsername.trim(),
password: customPassword.trim(), password: customPassword.trim(),
proxy: customProxy || undefined,
}; };
// Auto-save: Add credential immediately to persistent storage // Auto-save: Add credential immediately to persistent storage
@@ -265,7 +246,6 @@ export function GitSettings() {
setCustomOrigin(''); setCustomOrigin('');
setCustomUsername(''); setCustomUsername('');
setCustomPassword(''); setCustomPassword('');
setCustomProxy(false);
}; };
const handleRemoveCredential = (id: string) => { const handleRemoveCredential = (id: string) => {
@@ -559,16 +539,6 @@ export function GitSettings() {
onChange={(e) => setCustomPassword(e.target.value)} onChange={(e) => setCustomPassword(e.target.value)}
/> />
</div> </div>
<div className="flex items-center gap-2">
<Checkbox
id="custom-proxy"
checked={customProxy}
onCheckedChange={(checked) => setCustomProxy(checked === true)}
/>
<Label htmlFor="custom-proxy" className="cursor-pointer">
{t('useCorsProxy')}
</Label>
</div>
<Button <Button
onClick={handleAddCustomProvider} onClick={handleAddCustomProvider}
disabled={ disabled={
+1
View File
@@ -44,6 +44,7 @@ export function TestApp({ children }: TestAppProps) {
], ],
esmUrl: 'https://esm.shakespeare.diy', esmUrl: 'https://esm.shakespeare.diy',
corsProxy: 'https://proxy.shakespeare.diy/?url={href}', corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}', ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev', previewDomain: 'local-shakespeare.dev',