app/lib/context.ts
38 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| getEnv | 10 to 12 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| getNonce | 19 to 21 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| getExecutionContext | 42 to 46 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
Imports
It imports app/db/posts.ts. Imported by app/entry.server.tsx, app/kb/editor-route.server.ts, app/lib/carrel/site-adapter.server.ts, app/lib/carrel/site-api.server.ts, app/lib/citations.server.ts, app/lib/podcast/podcast.server.ts, app/root.tsx, app/routes/about.tsx, app/routes/admin._index.tsx, app/routes/admin.kb.preview.tsx, app/routes/admin.kb.tsx, app/routes/admin.media._index.tsx, app/routes/admin.media.upload.ts, app/routes/admin.mentions.tsx, app/routes/admin.posts.$slug.edit.tsx, app/routes/admin.posts.$slug.history.tsx, app/routes/admin.posts.$slug.revisions.tsx, app/routes/admin.posts._index.tsx, app/routes/admin.posts.new.tsx, app/routes/admin.preview.ts, app/routes/admin.tools.tsx, app/routes/admin.tsx, app/routes/api.csp-report.ts, app/routes/api.health.ts, app/routes/api.operator.ts, app/routes/blog.$slug.tsx, app/routes/blog.$slug[.md].ts, app/routes/blog._index.tsx, app/routes/blog.atom[.xml].ts, app/routes/blog.feed[.json].ts, app/routes/blog.rss[.xml].ts, app/routes/blog.series.$series.feed[.json].ts, app/routes/blog.series.$series.rss[.xml].ts, app/routes/blog.series.$series.tsx, app/routes/blog.tags.$tag.feed[.json].ts, app/routes/blog.tags.$tag.rss[.xml].ts, app/routes/blog.tags.$tag.tsx, app/routes/colophon.tsx, app/routes/content-page.tsx, app/routes/content-page[.md].ts, app/routes/cv-pdf.ts, app/routes/cv.charts[.json].ts, app/routes/cv.tsx, app/routes/cv[.md].ts, app/routes/home.tsx, app/routes/kb-library.tsx, app/routes/kb-library[.csv].ts, app/routes/kb-library[.json].ts, app/routes/kb-library[.md].ts, app/routes/lab.kind.tsx, app/routes/lab.tsx, app/routes/lab[.md].ts, app/routes/llms-full[.txt].ts, app/routes/llms.ts, app/routes/media.$.ts, app/routes/phages.tsx, app/routes/preview.$token.tsx, app/routes/procedure.sheet.tsx, app/routes/procedure.tsx, app/routes/procedure.version.sheet.tsx, app/routes/procedure.version.tsx, app/routes/procedure.version[.md].ts, app/routes/procedure[.md].ts, app/routes/protocols.tsx, app/routes/protocols[.csv].ts, app/routes/protocols[.json].ts, app/routes/protocols[.md].ts, app/routes/publications.$slug.tsx, app/routes/publications.$slug[.bib].ts, app/routes/publications.$slug[.md].ts, app/routes/publications.$slug[.ris].ts, app/routes/publications.tsx, app/routes/publications[.bib].ts, app/routes/publications[.json].ts, app/routes/publications[.ris].ts, app/routes/robots.ts, app/routes/search.ask.ts, app/routes/search.tsx, app/routes/site-map.tsx, app/routes/sitemap.ts, app/routes/webmention.ts, app/routes/workspace.inventory.lot.tsx, app/routes/workspace.inventory.tsx, app/routes/workspace.members.tsx, app/routes/workspace.runs.run.tsx, app/routes/workspace.runs.tsx, app/routes/workspace.tsx, workers/app.ts.
Source
import { createContext, type RouterContextProvider } from "react-router";
import type { previewBlogPost } from "~/db/posts";
export const cloudflareContext = createContext<{
env: Env;
ctx: ExecutionContext;
}>();
export function getEnv(context: Readonly<RouterContextProvider>): Env {
return context.get(cloudflareContext).env;
}
// Admin only. Unlike the other response headers, the nonce must exist before the render: the same
// value goes in the CSP header and on every `<script>` in the body. Public pages are edge-cached and
// carry none, so it is undefined there (workers/csp.mjs).
export const nonceContext = createContext<string | undefined>(undefined);
export function getNonce(context: Readonly<RouterContextProvider>): string | undefined {
return context.get(nonceContext);
}
/**
* The Renderer's own document handler, so the Carrel preview renders a page in-process through the
* site's routes and root layout. In-process, not a fetch to the Renderer: that entrypoint's response
* is the one the edge stores, and a preview must never be stored.
*/
// A null default, not undefined: React Router treats an undefined default as none, and a get of an
// unset context then throws, which would fail every request that never sets it.
export const documentHandlerContext = createContext<
((request: Request, context: RouterContextProvider) => Promise<Response>) | null
>(null);
/**
* Set only for a Carrel preview render: the post row built from submitted source, which the blog
* route renders in place of the stored row for that slug. Never set on a request from outside.
*/
export const postPreviewContext = createContext<
Awaited<ReturnType<typeof previewBlogPost>> | null
>(null);
export function getExecutionContext(
context: Readonly<RouterContextProvider>,
): ExecutionContext {
return context.get(cloudflareContext).ctx;
}