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
@@ -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',
-1
View File
@@ -162,7 +162,6 @@ describe('configUtils', () => {
origin: 'https://github.com',
username: 'user',
password: 'token123',
proxy: true,
},
],
};
-8
View File
@@ -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,
+15 -5
View File
@@ -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);
}
+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' }],
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',