Skip to content

Commit

Permalink
Point CDR Items at out of repo proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Jul 31, 2024
1 parent 8bb3926 commit 40e1744
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 40 deletions.
3 changes: 3 additions & 0 deletions packages/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -45,6 +47,7 @@ export const elevationLayerURL = getRuntimeConfig("ELEVATION_LAYER_URL");

/** Legacy settings object */
export const SETTINGS = {
cdrPrefix,
darkMapURL,
baseMapURL,
satelliteMapURL,
Expand Down
24 changes: 0 additions & 24 deletions pages/integrations/criticalmaas/cdr-proxy.server.ts

This file was deleted.

3 changes: 2 additions & 1 deletion pages/integrations/criticalmaas/ta1-results/+Page.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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}`;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pages/integrations/criticalmaas/ta1-results/util.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
9 changes: 1 addition & 8 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 40e1744

Please sign in to comment.