Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server updates #225

Merged
merged 18 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/web.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions content/.obsidian/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace.json
168 changes: 0 additions & 168 deletions content/.obsidian/workspace.json

This file was deleted.

5 changes: 5 additions & 0 deletions content/Community.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Macrostrat is part of a broad geoinformatics ecosystem.


## Cool Earth observing websites

https://earth.nullschool.net: weather and ocean-circulation visualizations
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"server:prod": "NODE_NO_WARNINGS=1 NODE_ENV=production yarn run server",
"dev:storybook": "yarn workspace @macrostrat/storybook run dev",
"start": "yarn run build && yarn run server",
"test:runtime": "tsx tests/test-urls.ts",
"test": "vitest"
},
"workspaces": [
Expand Down Expand Up @@ -146,9 +147,9 @@
"use-debounce": "^9.0.4",
"use-react-router-breadcrumbs": "^3.2.1",
"use-resize-observer": "^9.1.0",
"vike": "^0.4.172",
"vike-react": "^0.4.11",
"vite": "^5.2.11",
"vike": "^0.4.177",
"vike-react": "^0.4.15",
"vite": "^5.3.2",
"vite-plugin-cesium": "^1.2.22",
"vite-plugin-inspect": "^0.8.4",
"zustand": "^4.5.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/globe-dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import hyper from "@macrostrat/hyper";
import { MapPosition } from "@macrostrat/mapbox-utils";
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Link } from "~/renderer/Link";
import { Link } from "~/components/navigation/link-component";
import CesiumView from "./cesium-view";

import {
Expand Down
2 changes: 1 addition & 1 deletion packages/settings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getRuntimeConfig(
if (activeEnv === "server") {
// We are running on the server, try to get directly from process.env
val = process.env["VITE_" + key];
} else {
} else if (window.env !== undefined) {
// We are running on the client and have access to window.env
val = window.env[key];
}
Expand Down
6 changes: 3 additions & 3 deletions packages/sift/src/js/components/Column.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import h from "@macrostrat/hyper";
import React from "react";
import { useParams } from "react-router-dom";
import { Link as VikeLink } from "~/renderer/Link";
import { Link as VikeLink } from "~/components/navigation/link-component";
import Chart from "./Chart";
import Footer from "./Footer";
import { SiftLink } from "./Link";
Expand Down Expand Up @@ -285,13 +285,13 @@ class _Column extends React.Component {
<PrevalentTaxa data={this.state.prevalentTaxa} />

<StratColumn data={this.state.units} />
<VikeLink
<LinkComponent
href={"/columns/" + this.state.properties.col_id}
target="_blank"
className="normalize-link alternate-column"
>
Alternate column view
</VikeLink>
</LinkComponent>
</div>

<Footer data={this.state.refs} />
Expand Down
2 changes: 0 additions & 2 deletions packages/text-toolchain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default function viteTextToolchain({
const [pageIndex, permalinkIndex] = buildPageIndex(contentDir, wikiPrefix);
const permalinks = Object.keys(permalinkIndex);

console.log(pageIndex, permalinkIndex);

const include = [join(contentDir, "**/*.md"), "**/*.mdx"];

return mdx({
Expand Down
4 changes: 2 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function startServer() {

app.use(compression());
app.use(cookieParser());

//
if (isProduction) {
app.use(sirv(`${root}/dist/client`));
// Special case for cesium files at /cesium prefix
Expand Down Expand Up @@ -94,7 +94,7 @@ async function startServer() {
process.env.VITE_MACROSTRAT_TILESERVER_DOMAIN,
process.env.VITE_MACROSTRAT_INSTANCE
);

//
/**
* Vike route
*
Expand Down
10 changes: 7 additions & 3 deletions server/vike-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const environment = synthesizeConfigFromEnvironment();
export async function vikeHandler<
Context extends Record<string | number | symbol, unknown>
>(request: Request, context?: Context): Promise<Response> {
const baseContext = context ?? {};
const user = await getUserFromCookie(request);

const pageContextInit = {
...baseContext,
...context,
urlOriginal: request.url,
environment,
user,
Expand All @@ -21,7 +21,11 @@ export async function vikeHandler<
const pageContext = await renderPage(pageContextInit);
const response = pageContext.httpResponse;

return new Response(response?.getReadableWebStream(), {
const { readable, writable } = new TransformStream();

response?.pipe(writable);

return new Response(readable, {
status: response?.statusCode,
headers: response?.headers,
});
Expand Down
9 changes: 9 additions & 0 deletions src/_providers.client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import h from "@macrostrat/hyper";
import { resolvePattern, onDemand } from "~/_utils";
import { GeologicPatternProvider } from "@macrostrat/column-components";
// Import the pattern provider if on the client side
// This is a wrapper around the GeologicPatternProvider from column-components

export function PatternProvider({ children }) {
return h(GeologicPatternProvider, { resolvePattern }, children);
}
20 changes: 10 additions & 10 deletions src/renderer/auth.ts → src/_providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
AsyncAuthAction,
} from "@macrostrat/auth-components";
import h from "@macrostrat/hyper";
import { ingestPrefix } from "@macrostrat-web/settings";
import { ingestPrefix } from "../../packages/settings";

async function authTransformer(
action: AuthAction | AsyncAuthAction
Expand All @@ -25,11 +25,11 @@ async function authTransformer(
case "logout":
// Delete the token from the session
try {
const response = await fetch(
`${ingestPrefix}/security/logout`,
{ method: "POST", credentials: "include"}
);
if(response.ok){
const response = await fetch(`${ingestPrefix}/security/logout`, {
method: "POST",
credentials: "include",
});
if (response.ok) {
return { type: "logout" };
} else {
throw new Error("Failed to logout");
Expand All @@ -55,12 +55,12 @@ export function AuthProvider(props) {
export async function fetchUser() {
const response = await fetch(`${ingestPrefix}/security/me`, {
method: "GET",
credentials: "include"
credentials: "include",
});
if(response.ok){
if (response.ok) {
const user = await response.json();
return user
return user;
} else {
throw new Error("Failed to get user status");
}
}
}
9 changes: 2 additions & 7 deletions src/_providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
import { GeologicPatternProvider } from "@macrostrat/column-components";
import h from "@macrostrat/hyper";
import { resolvePattern } from "~/_utils";

export function PatternProvider({ children }) {
return h(GeologicPatternProvider, { resolvePattern }, children);
}
export * from "./postgrest";
export * from "./auth";
File renamed without changes.
4 changes: 1 addition & 3 deletions src/renderer/client-only.ts → src/_utils/client-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import loadable from "@loadable/component";
import h from "@macrostrat/hyper";
import { Suspense, useEffect, useMemo, useState } from "react";

function ClientOnly(props) {
export function ClientOnly(props) {
const fallback = props.fallback || Spinner;
const [Component, setComponent] = useState(null);
const rest = useMemo(() => {
Expand All @@ -19,5 +19,3 @@ function ClientOnly(props) {

return h(Suspense, { fallback: fallback }, element);
}

export { ClientOnly };
2 changes: 2 additions & 0 deletions src/_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export function loadableElement(func, props = null) {
export function resolvePattern(name: string | number) {
return `//visualization-assets.s3.amazonaws.com/geologic-patterns/svg/${name}.svg`;
}

export * from "./client-only";
Loading
Loading