{"id":48355976,"url":"https://github.com/brandonpittman/remix-pages-context","last_synced_at":"2026-04-05T11:05:16.579Z","repository":{"id":57674381,"uuid":"483079843","full_name":"brandonpittman/remix-pages-context","owner":"brandonpittman","description":"A module to make using Cloudflare Pages environment variables and KV-backed sessions easier with Remix.","archived":false,"fork":false,"pushed_at":"2023-04-29T07:13:39.000Z","size":152,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-04T05:32:01.839Z","etag":null,"topics":["cloudflare","environment-variables","remix","schema","sessions","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandonpittman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-04-19T03:21:47.000Z","updated_at":"2024-10-06T20:51:33.000Z","dependencies_parsed_at":"2024-01-07T06:11:24.366Z","dependency_job_id":"470054f6-6716-438a-9491-097484b90f18","html_url":"https://github.com/brandonpittman/remix-pages-context","commit_stats":{"total_commits":138,"total_committers":1,"mean_commits":138.0,"dds":0.0,"last_synced_commit":"9eaf0fba9c9824c47215d9852c6d50f4cc5aaa24"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"purl":"pkg:github/brandonpittman/remix-pages-context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonpittman%2Fremix-pages-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonpittman%2Fremix-pages-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonpittman%2Fremix-pages-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonpittman%2Fremix-pages-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonpittman","download_url":"https://codeload.github.com/brandonpittman/remix-pages-context/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonpittman%2Fremix-pages-context/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31433044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T08:13:15.228Z","status":"ssl_error","status_checked_at":"2026-04-05T08:13:11.839Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","environment-variables","remix","schema","sessions","zod"],"created_at":"2026-04-05T11:05:12.891Z","updated_at":"2026-04-05T11:05:16.519Z","avatar_url":"https://github.com/brandonpittman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# remix-pages-context\n\nThis package lets you use Cloudflare Pages' environment variables and KV-backed sessions more easily.\nSome setup is requried.\n\n## Install\n\n```sh\nnpm install remix-pages-context\n```\n\n## Set up `server.ts`\n\n1. Create a typed context object, passing in Zod schemas for your ENV variables and session values\n2. Destructure `getLoadContext` and `getPagesContext` off the object\n3. Pass `getLoadContext` into `createPagesFunctionHandler`\n4. Use `getPagesContext` anywhere you want to access your typed ENV variables and session values\n\n```ts\nimport { createPagesFunctionHandler } from \"@remix-run/cloudflare-pages\";\nimport * as build from \"@remix-run/dev/server-build\";\nimport { createTypedPagesContext } from \"remix-pages-context\";\nimport { z } from \"zod\";\n\nexport let contextSchema = z.object({\n  SESSION_SECRET: z.string(),\n  // other ENV vars...\n});\n\nexport let sessionSchema = z.object({\n  someValue: z.string().optional(),\n});\n\nexport let { getLoadContext, getPagesContext } = createTypedPagesContext({\n  contextSchema,\n  sessionSchema,\n});\n\nconst handleRequest = createPagesFunctionHandler({\n  build,\n  mode: process.env.NODE_ENV,\n  getLoadContext,\n});\n\nexport function onRequest(context: EventContext\u003cany, any, any\u003e) {\n  return handleRequest(context);\n}\n```\n\n## Optional Typed Sessions\n\nIf you provide a Zod schema for `sessionSchema` like this:\n\n```\ncreateTypedPagesContext({ contextSchema, sessionSchema })\n```\n\n…you will get a [typed session from Remix Utils](https://github.com/sergiodxa/remix-utils#typed-sessions).\n\n### KV Session\n\nEnable Cloudflare KV session storage when you create a KV namespace named `KV` and\nan environment variable named `SESSION_SECRET`. The factory function takes a\nsecond param of `CookieOptions` if you want to customize the underlying cookie\nthat's used for the session storage.\n\n## Use the context\n\nIn loaders, you can access `context` along with `request` and `params`, but it won't be typed. Better to use it like this:\n\n```ts\nexport let loader = async() {\n  let { env, sessionStorage } = getPagesContext();\n}\n```\n\nThen, in any other module, call `getPagesContext()` to access the context set in `server.ts`.\n\n## Limitations\n\nIf you call `getPagesContext()` in a `*.server.ts` module, you need to call it in a function because it will be `undefined`\nuntil the `loader` in `root.tsx` is run.\n\n```ts\n// foo.server.ts\nimport { getPagesContext } from \"server\";\n\nexport let foo = async () =\u003e {\n  let { env, sessionStorage } = getPagesContext();\n  // do something with context\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonpittman%2Fremix-pages-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonpittman%2Fremix-pages-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonpittman%2Fremix-pages-context/lists"}