-
Notifications
You must be signed in to change notification settings - Fork 40
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 extending a serve handler by overriding the existing isProduction #425
Conversation
|
A user has added the prerelease/inngest label, so this PR will be published to npm with the tag You can install this prerelease version with: npm install inngest@pr-425 The last release was built and published from caf0316. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is a weird DX that this is isProduction
which the dev then may only want sometimes to opt-out of production checks, but they may want the production checks that already exist by default.
Thinking through the usage of this for integration testing, you might see this and say, if I set this to false, that should make it not act as it was in prod, but that' snot true due to the check in the comm handler's constructor:
export default serve({
client: inngest,
functions,
// Setting false will not work - I want to opt-out, not opt in
isProduction: !!process.env.INTEGRATION_TEST ?
false :
// I'd still want to default NODE_ENV check to work
// so I don't want to say if not integration test, then true
undefined,
});
INTEGRATION_TEST=1 node ./index.js # this won't work right if NODE_ENV=production
So then to solve this in the current code where there is the options.isProduction
check within the comm handler's constructor
, you'd have to make it a function:
export default serve({
client: inngest,
functions,
// Function has to return undefined to fallback to the default NODE_ENV check
// w/ the nullish coalescing in handleAction
isProduction: () => !!process.env.INTEGRATION_TEST ?
false :
undefined,
});
INTEGRATION_TEST=1 node ./index.js
It feels a bit cumbersome to basically just opt-out of the signing key security checks. Our customer had an interesting thought of just making this more explicit like disableProductionChecks: boolean
which is more of an opt-in than the current approach.
export default serve({
client: inngest,
functions,
// Some positives:
// - The user can customize this as needed
// - It's less clever - more straightforward what this does
// - It clearly demonstrates some sort of risk if you opt-out
disableProductionChecks: () => !!process.env.INTEGRATION_TEST
});
Sharing this in the PR for transparency/posterity 😄
@jpwilliams, a user tried this feature and experienced some issues. Linking the conversation.. |
Thanks, @IGassmann. Closing this now. Superseded by #488. |
## Summary <!-- Succinctly describe your change, providing context, what you've changed, and why. --> Adds support for `INNGEST_DEV` and a new `isDev` option on the client. This lightly refactors the current checks based around `isProd` and `skipDevServer()`, which were getting a little difficult to read. - The SDK now has two "modes:" `"dev"` and `"cloud"`. - Each mode is either **explicit** or **inferred**. An inferred mode means that the current (`v3.x.x`) version of the SDK can make a decision to attempt to contact the Dev Server. Future versions will remove this and default to `"cloud"` mode. - Setting the `INNGEST_DEV` environment variable or the `isDev` client option **explicitly** sets the mode to either `"cloud"` or `"dev"`. - `INNGEST_DEV` accepts some sensible defaults. We'll recommend `1` to explicitly set `"dev"` mode and `0` to explicitly set `"cloud"` mode, though it also accepts `"true"`, `"y"`, `"no"`, etc. - Explicitly setting either mode also sets the event ingestion and syncing URLs. They continue to be further overwritten by passing `INNGEST_BASE_URL`, `INNGEST_API_BASE_URL`, and `INNGEST_EVENT_API_BASE_URL`. > [!NOTE] > To support many runtimes and environments, environment variables are not always accessible a) at all times, and b) on `process.env`. Sometimes environment variables are accessed via different global objects, or sometimes runtime objects that are passed to requests. > > For this reason, handling environment variables is more complex and relies on making best guesses during instantiation, then later making another decision when we have access to the environment. Supersedes both #424 and #425. ## Checklist <!-- Tick these items off as you progress. --> <!-- If an item isn't applicable, ideally please strikeout the item by wrapping it in "~~"" and suffix it with "N/A My reason for skipping this." --> <!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" --> - [x] Added a [docs PR](https://github.com/inngest/website) documenting these modes and the new environment variables that references this PR - [x] Added unit/integration tests - [x] Added changesets if applicable - [x] Push env-related changes to the OS SDK Spec ## Related <!-- A space for any related links, issues, or PRs. --> <!-- Linear issues are autolinked. --> <!-- e.g. - INN-123 --> <!-- GitHub issues/PRs can be linked using shorthand. --> <!-- e.g. "- inngest/inngest#123" --> <!-- Feel free to remove this section if there are no applicable related links.--> - INN-2754 - Supersedes #424 - Supersedes #425 - inngest/website#679
Summary
Allows users to override the existing
isProduction
check performed by serve handlers, providing their own value (or dynamic value).Note
Not specifying the value--or if the value or dynamic value is
undefined
--will ensure the SDK falls back to using the current production checks.It's specified on the
serve()
handler as they already need to be able to decide for themselves whether they're in production mode, as some pieces of the puzzle (like environment variables) are not available until the request enters the system.Therefore, this is the first part of allowing users to extend existing serve handlers to override pieces of functionality such as production checks, URL creation, or accessing environment variables.
Checklist
Related