nginx
This commit is contained in:
@@ -7,17 +7,11 @@ import { LEGACY_BASE_URL, REST_BASE_URL } from '../data/topics'
|
|||||||
const ADMIN_SECRET = 'nearle-admin-secret'
|
const ADMIN_SECRET = 'nearle-admin-secret'
|
||||||
|
|
||||||
function toProxyPath(fullUrl) {
|
function toProxyPath(fullUrl) {
|
||||||
// REST: jupiter.nearle.app lacks CORS headers, so we MUST proxy it.
|
// Legacy (api.workolik.com): We still proxy this to inject the admin secret via server
|
||||||
if (fullUrl.startsWith(REST_BASE_URL)) {
|
if (fullUrl.startsWith(LEGACY_BASE_URL)) {
|
||||||
// Locally, Vite intercepts /live/... and proxies it perfectly.
|
return fullUrl.slice(LEGACY_BASE_URL.length)
|
||||||
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.
|
// REST API (jupiter.nearle.app): Has native CORS enabled, browser hits it directly!
|
||||||
return fullUrl
|
return fullUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +46,13 @@ export default function TopicView({ topic, searchQuery }) {
|
|||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const headers = { 'Content-Type': 'application/json' }
|
const headers = {}
|
||||||
if (topic.type === 'legacy') headers['x-hasura-admin-secret'] = ADMIN_SECRET
|
if (endpoint.method !== 'GET') {
|
||||||
|
headers['Content-Type'] = 'application/json'
|
||||||
|
}
|
||||||
|
if (topic.type === 'legacy') {
|
||||||
|
headers['x-hasura-admin-secret'] = ADMIN_SECRET
|
||||||
|
}
|
||||||
|
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: endpoint.method,
|
method: endpoint.method,
|
||||||
|
|||||||
Reference in New Issue
Block a user