diff --git a/packages/settings/index.ts b/packages/settings/index.ts index ef38ea25..4bd7856d 100644 --- a/packages/settings/index.ts +++ b/packages/settings/index.ts @@ -31,6 +31,8 @@ export const ingestPrefix = getRuntimeConfig( apiDomain + "/api/ingest" ); +export const cdrPrefix = getRuntimeConfig("CDR_API"); + export const mapPagePrefix = "/map"; export const routerBasename = "/map"; @@ -45,6 +47,7 @@ export const elevationLayerURL = getRuntimeConfig("ELEVATION_LAYER_URL"); /** Legacy settings object */ export const SETTINGS = { + cdrPrefix, darkMapURL, baseMapURL, satelliteMapURL, diff --git a/pages/integrations/criticalmaas/cdr-proxy.server.ts b/pages/integrations/criticalmaas/cdr-proxy.server.ts deleted file mode 100644 index afdd6af4..00000000 --- a/pages/integrations/criticalmaas/cdr-proxy.server.ts +++ /dev/null @@ -1,24 +0,0 @@ -// CriticalMAAS CDR integration -// Proxy requests to /tile/* to https://api.cdr.land/v1/tiles/* -// Add the Authorization header to the proxied request -// - -import proxy from "express-http-proxy"; - -export function createCDRProxy() { - // TODO: CDR needs to accept authentication so that we can stop proxying requests. - // OR tile endpoints need to be public. - const proxyAddress = process.env.CDR_API_BASE ?? "https://api.cdr.land"; - const proxyToken = process.env.CDR_API_KEY; - - if (!proxyToken || !proxyAddress) { - return null; - } - - return proxy(proxyAddress, { - proxyReqOptDecorator: (opts) => { - opts.headers["Authorization"] = `Bearer ${proxyToken}`; - return opts; - }, - }); -} diff --git a/pages/integrations/criticalmaas/ta1-results/+Page.ts b/pages/integrations/criticalmaas/ta1-results/+Page.ts index 932354e3..c92d7475 100644 --- a/pages/integrations/criticalmaas/ta1-results/+Page.ts +++ b/pages/integrations/criticalmaas/ta1-results/+Page.ts @@ -1,5 +1,6 @@ import h from "@macrostrat/hyper"; // Page for a list of maps +import { cdrPrefix } from "@macrostrat-web/settings"; import { AnchorButton, ButtonGroup, Spinner } from "@blueprintjs/core"; import { ContentPage } from "~/layouts"; import { PageHeader } from "~/components"; @@ -13,7 +14,7 @@ export function Page() { useEffect(() => { setLoading(true); - getMapSources(window.location.origin, page).then((d) => { + getMapSources(cdrPrefix, page).then((d) => { setSources(d); setLoading(false); }); diff --git a/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+Page.ts b/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+Page.ts index 29e2664e..b575fa32 100644 --- a/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+Page.ts +++ b/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+Page.ts @@ -1,7 +1,7 @@ import { Radio, RadioGroup, Spinner } from "@blueprintjs/core"; import { useData } from "vike-react/useData"; -import { SETTINGS } from "@macrostrat-web/settings"; +import { SETTINGS, cdrPrefix } from "@macrostrat-web/settings"; import hyper from "@macrostrat/hyper"; import { DetailPanelStyle, @@ -164,7 +164,7 @@ export default function MapInterface() { raster: 0.5, }); - const tileURL = `${baseURL}/cdr/v1/tiles/cog/${cog_id}/system/${encodeURIComponent( + const tileURL = `${cdrPrefix}/tiles/polygon/cog/${cog_id}/system/${encodeURIComponent( system )}/system_version/${encodeURIComponent(system_version)}/tile/{z}/{x}/{y}`; diff --git a/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+data.ts b/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+data.ts index b8347d06..a924a7f6 100644 --- a/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+data.ts +++ b/pages/integrations/criticalmaas/ta1-results/@cog_id/@system/@system_version/+data.ts @@ -1,17 +1,16 @@ import { PageContext } from "vike/types"; +import { cdrPrefix } from "@macrostrat-web/settings"; export async function data(pageContext: PageContext) { const { cog_id, system, system_version } = pageContext.routeParams; const baseURL = pageContext.urlParsed.origin; - const url = `${baseURL}/cdr/v1/tiles/cog/${cog_id}/system/${system}/system_version/${system_version}`; + const url = `${cdrPrefix}/tiles/cog/${cog_id}/system/${system}/system_version/${system_version}`; const res = await fetch(url); const data = await res.json(); // Get projected COG info - const projInfo = await fetch( - `${baseURL}/cdr/v1/maps/cog/projections/${cog_id}` - ); + const projInfo = await fetch(`${cdrPrefix}/maps/cog/projections/${cog_id}`); const projData = await projInfo.json(); // Get first validated projection diff --git a/pages/integrations/criticalmaas/ta1-results/util.ts b/pages/integrations/criticalmaas/ta1-results/util.ts index 3f9194df..cfac29ce 100644 --- a/pages/integrations/criticalmaas/ta1-results/util.ts +++ b/pages/integrations/criticalmaas/ta1-results/util.ts @@ -1,5 +1,5 @@ export async function getMapSources(baseURL, page) { - const url = new URL(baseURL + "/cdr/v1/tiles/sources"); + const url = new URL(baseURL + "/tiles/sources"); url.searchParams.set("page_size", 10); url.searchParams.set("page", page); const res = await fetch(url); diff --git a/server/index.ts b/server/index.ts index d604fc1f..1cf36c70 100644 --- a/server/index.ts +++ b/server/index.ts @@ -8,14 +8,13 @@ import { createMiddleware } from "@universal-middleware/express"; import { createMacrostratQlrAPI } from "@macrostrat-web/qgis-integration"; import express from "express"; import sirv from "sirv"; -import { createCDRProxy } from "../pages/integrations/criticalmaas/cdr-proxy.server"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const isProduction = process.env.NODE_ENV === "production"; // Serve the app out of the `src` directory. const root = resolve(join(__dirname, "..")); -const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000; +const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3003; const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678; @@ -96,12 +95,6 @@ async function startServer() { process.env.VITE_MACROSTRAT_INSTANCE ); - // CriticalMAAS CDR integration - // Proxy requests to /* to https://api.cdr.land/* - // Add the Authorization header to the proxied request - // TODO: put this behind authorization, perhaps move to a separate service - app.use("/cdr", createCDRProxy()); - /** * Vike route *