nginx
This commit is contained in:
@@ -7,12 +7,16 @@ 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)) {
|
||||
// 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user