mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:35:24 +02:00
feat: Vercel serverless proxy for Dropbox (fix deploy issues) && update App.tsx
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user