PozoApp.dev-optimized-and-D.../config.js

47 lines
1.3 KiB
JavaScript

// CDN Configuration for React + Vite + JavaScript
// Auto detect localhost vs production - No environment variable needed!
const getCDNBase = () => {
// Vite environment variable check first (optional)
if (import.meta.env.VITE_CDN_URL) {
return import.meta.env.VITE_CDN_URL;
}
// Browser la automatic detection
if (typeof window !== "undefined") {
const hostname = window.location.hostname;
// Local development
if (hostname === "localhost" || hostname === "127.0.0.1") {
return "http://192.168.1.26/home/assets";
}
// Production - pozo.dev or pozo.app
if (hostname.includes("pozo.dev") || hostname.includes("pozo.app")) {
return "http://192.168.1.26/home/assets";
}
// Default - use current protocol and hostname
return `${window.location.protocol}//${hostname}/home/assets`;
}
// Fallback
return "http://192.168.1.26/home/assets";
};
// Export CDN base URL (ready to use!)
export const CDN_BASE = getCDNBase();
// Helper function to get full CDN URL
export const getCDNUrl = (filename) => {
// Remove leading slash if present
const cleanFilename = filename.startsWith("/") ? filename.slice(1) : filename;
return `${CDN_BASE}/${cleanFilename}`;
};
// Default export
export default {
CDN_BASE,
getCDNUrl,
};