mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Swap out corsproxy.io for our custom proxy
This commit is contained in:
6 files changed
+35
-25
No files matched your search
@@ -61,7 +61,7 @@ describe('useGitHubOAuth PKCE', () => {
|
||||
wrapper: TestApp,
|
||||
});
|
||||
|
||||
// Mock fetch for token exchange and user info (using corsproxy.io URLs)
|
||||
// Mock fetch for token exchange and user info (using proxy URLs)
|
||||
const mockFetch = vi.fn()
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
@@ -147,7 +147,7 @@ describe('useGitHubOAuth PKCE', () => {
|
||||
|
||||
// Check that the token request includes the code verifier
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining('corsproxy.io/?url=https://github.com/login/oauth/access_token'),
|
||||
'https://proxy.shakespeare.diy/?url=https%3A%2F%2Fgithub.com%2Flogin%2Foauth%2Faccess_token',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: expect.stringContaining('"code_verifier":"test-verifier"'),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useGitSettings } from './useGitSettings';
|
||||
import { proxyUrl } from '@/lib/proxyUrl';
|
||||
|
||||
interface GitHubOAuthState {
|
||||
isLoading: boolean;
|
||||
@@ -17,7 +18,8 @@ export function useGitHubOAuth() {
|
||||
isLoading: false,
|
||||
error: null,
|
||||
});
|
||||
const { addCredential } = useGitSettings();
|
||||
const { settings, addCredential } = useGitSettings();
|
||||
const { corsProxy } = settings;
|
||||
|
||||
// Check if OAuth is configured
|
||||
const isOAuthConfigured = !!(
|
||||
@@ -122,7 +124,8 @@ export function useGitHubOAuth() {
|
||||
code_verifier: codeVerifier,
|
||||
};
|
||||
|
||||
const tokenResponse = await fetch('https://corsproxy.io/?url=https://github.com/login/oauth/access_token', {
|
||||
const tokenUrl = proxyUrl(corsProxy, 'https://github.com/login/oauth/access_token');
|
||||
const tokenResponse = await fetch(tokenUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
@@ -142,7 +145,8 @@ export function useGitHubOAuth() {
|
||||
}
|
||||
|
||||
// Get user info to verify the token works
|
||||
const userResponse = await fetch('https://corsproxy.io/?url=https://api.github.com/user', {
|
||||
const userUrl = proxyUrl(corsProxy, 'https://api.github.com/user');
|
||||
const userResponse = await fetch(userUrl, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${tokenData.access_token}`,
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
@@ -177,7 +181,7 @@ export function useGitHubOAuth() {
|
||||
}));
|
||||
return false;
|
||||
}
|
||||
}, [addCredential]);
|
||||
}, [addCredential, corsProxy]);
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('CurlCommand', () => {
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toBe('Hello World');
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://proxy.shakespeare.diy/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
method: 'GET',
|
||||
headers: expect.objectContaining({
|
||||
'User-Agent': 'curl/8.0.0 (compatible; JavaScript fetch)'
|
||||
@@ -103,7 +103,7 @@ describe('CurlCommand', () => {
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toBe('{"success": true}');
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2Fapi', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://proxy.shakespeare.diy/?url=https%3A%2F%2Fexample.com%2Fapi', expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: '{"name": "test"}',
|
||||
headers: expect.objectContaining({
|
||||
@@ -131,7 +131,7 @@ describe('CurlCommand', () => {
|
||||
], '/test');
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://proxy.shakespeare.diy/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
headers: expect.objectContaining({
|
||||
'Authorization': 'Bearer token123',
|
||||
'Content-Type': 'application/json',
|
||||
@@ -245,7 +245,7 @@ describe('CurlCommand', () => {
|
||||
], '/test');
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://corsproxy.io/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
expect(mockFetch).toHaveBeenCalledWith('https://proxy.shakespeare.diy/?url=https%3A%2F%2Fexample.com%2F', expect.objectContaining({
|
||||
method: 'DELETE',
|
||||
headers: expect.objectContaining({
|
||||
'User-Agent': 'curl/8.0.0 (compatible; JavaScript fetch)'
|
||||
|
||||
@@ -62,7 +62,7 @@ export class CurlCommand implements ShellCommand {
|
||||
|
||||
// Proxy the URL through CorsProxy
|
||||
const originalUrl = url.toString();
|
||||
const proxiedUrl = `https://corsproxy.io/?url=${encodeURIComponent(originalUrl)}`;
|
||||
const proxiedUrl = `https://proxy.shakespeare.diy/?url=${encodeURIComponent(originalUrl)}`;
|
||||
|
||||
// Prepare request
|
||||
const requestInit: RequestInit = {
|
||||
|
||||
+2
-14
@@ -1,7 +1,7 @@
|
||||
import git, { GitHttpRequest, GitHttpResponse, HttpClient } from 'isomorphic-git';
|
||||
import { NIP05 } from '@nostrify/nostrify';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import UriTemplate from 'uri-templates';
|
||||
import { proxyUrl } from './proxyUrl';
|
||||
import type { NostrEvent, NostrSigner, NPool } from '@nostrify/nostrify';
|
||||
import type { JSRuntimeFS } from './JSRuntime';
|
||||
|
||||
@@ -1626,19 +1626,7 @@ class GitHttp implements HttpClient {
|
||||
const url = new URL(request.url);
|
||||
|
||||
const target = this.proxy
|
||||
? UriTemplate(this.proxy).fill({
|
||||
href: url.href,
|
||||
origin: url.origin,
|
||||
protocol: url.protocol,
|
||||
username: url.username,
|
||||
password: url.password,
|
||||
host: url.host,
|
||||
hostname: url.hostname,
|
||||
port: url.port,
|
||||
pathname: url.pathname,
|
||||
hash: url.hash,
|
||||
search: url.search,
|
||||
})
|
||||
? proxyUrl(this.proxy, url)
|
||||
: url.href;
|
||||
|
||||
const init: RequestInit = {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import UriTemplate from 'uri-templates';
|
||||
|
||||
export function proxyUrl(template: string, url: string | URL): string {
|
||||
const u = new URL(url);
|
||||
return UriTemplate(template).fill({
|
||||
href: u.href,
|
||||
origin: u.origin,
|
||||
protocol: u.protocol,
|
||||
username: u.username,
|
||||
password: u.password,
|
||||
host: u.host,
|
||||
hostname: u.hostname,
|
||||
port: u.port,
|
||||
pathname: u.pathname,
|
||||
hash: u.hash,
|
||||
search: u.search,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user