Skip to content

Commit

Permalink
Support Remix env vars on Cloudflare Pages via context.env
Browse files Browse the repository at this point in the history
  • Loading branch information
jpwilliams committed Nov 24, 2023
1 parent 4066217 commit 9921077
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/inngest/src/components/InngestCommHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ export type Handler<
export type HandlerResponse<Output = any, StreamOutput = any> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: () => MaybePromise<any>;
env?: () => MaybePromise<Env>;
env?: () => MaybePromise<Env | undefined>;
headers: (key: string) => MaybePromise<string | null | undefined>;

/**
Expand Down
21 changes: 20 additions & 1 deletion packages/inngest/src/remix.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { z } from "zod";
import {
InngestCommHandler,
type ActionResponse,
type ServeHandlerOptions,
} from "./components/InngestCommHandler";
import { type Env } from "./helpers/env";
import { type SupportedFrameworkName } from "./types";

export const frameworkName: SupportedFrameworkName = "remix";
Expand Down Expand Up @@ -56,11 +58,28 @@ const createNewResponse = ({
* @public
*/
export const serve = (options: ServeHandlerOptions) => {
const contextSchema = z.object({
env: z.record(z.string(), z.any()),
});

const handler = new InngestCommHandler({
frameworkName,
...options,
handler: ({ request: req }: { request: Request }) => {
handler: ({
request: req,
context,
}: {
request: Request;
context?: unknown;
}) => {
return {
env: () => {
const ctxParse = contextSchema.safeParse(context);

if (ctxParse.success && Object.keys(ctxParse.data.env).length) {
return ctxParse.data.env as Env;
}
},
body: () => req.json(),
headers: (key) => req.headers.get(key),
method: () => req.method,
Expand Down

0 comments on commit 9921077

Please sign in to comment.