This commit is contained in:
2026-05-20 18:22:29 +05:30
parent 57ef8fb55c
commit fbbffb9567

View File

@@ -7,11 +7,15 @@ import { LEGACY_BASE_URL, REST_BASE_URL } from '../data/topics'
const ADMIN_SECRET = 'nearle-admin-secret'
function toProxyPath(fullUrl) {
// REST: always strip to a relative /live/... path so the request goes through
// the local server proxy (Vite dev/preview, or nginx in production).
// This avoids CORS entirely — the browser never talks to jupiter.nearle.app directly.
// REST: jupiter.nearle.app lacks CORS headers, so we MUST proxy it.
if (fullUrl.startsWith(REST_BASE_URL)) {
return fullUrl.slice(REST_BASE_URL.length)
// Locally, Vite intercepts /live/... and proxies it perfectly.
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
return fullUrl.slice(REST_BASE_URL.length)
}
// In production, since we cannot configure the host server (like Nginx),
// we use a public CORS proxy to bridge the request directly from the browser!
return 'https://corsproxy.io/?url=' + encodeURIComponent(fullUrl)
}
// Legacy (api.workolik.com): CORS is open, admin secret injected in headers.
return fullUrl