Skip to content

Commit

Permalink
Pass getLoaderContext into [[page]] function
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Jun 21, 2024
1 parent c91f97a commit 7f9c6a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
6 changes: 2 additions & 4 deletions app/routes/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ export const meta: MetaFunction = () => {
const MAX_RETENTION_DAYS = 90;

export const loader = async ({ context, request }: LoaderFunctionArgs) => {
// NOTE: probably duped from getLoadContext / need to de-duplicate
if (
!context.cloudflare.env.CF_BEARER_TOKEN ||
!context.cloudflare.env.CF_ACCOUNT_ID
) {
throw new Error("Missing Cloudflare credentials");
}

const analyticsEngine = new AnalyticsEngineAPI(
context.cloudflare.env.CF_ACCOUNT_ID,
context.cloudflare.env.CF_BEARER_TOKEN,
);
const { analyticsEngine } = context;

const url = new URL(request.url);

Expand Down
3 changes: 3 additions & 0 deletions functions/[[page]].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages";

import * as build from "../build/server";

Check failure on line 3 in functions/[[page]].ts

View workflow job for this annotation

GitHub Actions / test

Unable to resolve path to module '../build/server'

import { getLoadContext } from "../load-context";

export const onRequest = createPagesFunctionHandler({
// @ts-expect-error - the server build file is generated by `remix vite:build`
build,
getLoadContext,
});
11 changes: 0 additions & 11 deletions load-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ declare module "@remix-run/cloudflare" {
}
}

// declare module "@remix-run/server-runtime" {
// export interface AppLoadContext {
// analyticsEngine: AnalyticsEngineAPI;
// env: {
// VERSION: string;
// CF_BEARER_TOKEN: string;
// CF_ACCOUNT_ID: string;
// };
// }
// }

type GetLoadContext = (args: {
request: Request;
context: { cloudflare: Cloudflare }; // load context _before_ augmentation
Expand Down

0 comments on commit 7f9c6a2

Please sign in to comment.