feat: Vercel serverless proxy for Dropbox (fix deploy issues) && update App.tsx

This commit is contained in:
Christian Vidal Wolf
2026-01-16 10:50:39 +01:00
parent a1ad3aa944
commit e271d9d5ba
4 changed files with 1906 additions and 17 deletions
+8 -14
View File
@@ -61,22 +61,16 @@ const App: React.FC = () => {
directUrl = urlObject.toString();
}
let fetchUrl = directUrl;
// Check if we are in a local environment to use the Vite proxy
const isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
// Unified Fetch Logic for Local (Vite) and Production (Vercel Function)
// Both environments now support the /api/dropbox/... path.
// - Local: Vite proxies /api/dropbox -> https://www.dropbox.com
// - Vercel: api/dropbox.js handles the request -> https://www.dropbox.com
if (isLocal && url.includes('dropbox.com')) {
// Extract path and query from the direct URL
const urlObj = new URL(directUrl);
// Pass the necessary query params including st and dl=1
const searchParams = urlObj.search;
fetchUrl = `/api/dropbox${urlObj.pathname}${searchParams}`;
} else {
// Production or non-local fallback: Use CORS proxy
// Using allorigins.win as a fallback if not local
fetchUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(directUrl)}`;
}
const urlObj = new URL(directUrl);
const searchParams = urlObj.search;
// Construct path relative to root: /api/dropbox/scl/fi/...
const fetchUrl = `/api/dropbox${urlObj.pathname}${searchParams}`;
const response = await fetch(fetchUrl);
if (!response.ok) throw new Error(`Failed to fetch CSV from URL: ${response.status} ${response.statusText}`);