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

Allow for configuration via serve #629

Open
goszczynskip opened this issue Jun 27, 2024 · 1 comment
Open

Allow for configuration via serve #629

goszczynskip opened this issue Jun 27, 2024 · 1 comment

Comments

@goszczynskip
Copy link
Contributor

In a monorepo setup where Inngest functions live in a separate package, there's no solution to pass runtime configuration to functions.

apps
 └── nextjs
     └── app
         └── api
             └── inngest
                 └── route.tsx (serve is called there)
packages
 └── inngest
     └── functions
         └── myfunction.ts
     └── index.ts (middleware is setup here)

The Inngest package is a dependency of the Nextjs app. So it shouldn't import exported values from it since it will introduce cycle.

My proposed solution

I want to pass custom configuration data via serve to the client init function so I can set up the parametrized context. This follows the same context creation logic proposed by tRPC. Example from create-t3-turbo

// nextjs api route
import { inngest } from "@acme/inngest" // custom package in monorepo
import { functions } from "@acme/inngest/functions"

serve({
  client: inngest,
  functions,
  ctx: inngest.createContext({
     myProp: "myValue"
  })
})
// packages/inngest

interface InitialContext {
  myValue: string
}

const i = new Inngest<InitialContext>({
  schemas: new EventSchemas().fromRecord<Events>()
})

const middleware = i.createMiddleware({
  name: "Test Middleware",
  // here come values from serve
  init({ client, ctx }) {
    return {
       ...
    };
  };
});

export const inngest = i.use(middleware)

Describe alternatives you've considered

I considered accessing process.env.ENV_VAR directly in inngest package. This is suboptimal due to the lack of type safety. Also, this limits me only to process.env usage.

Copy link

linear bot commented Jun 27, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant