inngest / inngest-js

The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript
https://www.inngest.com/
GNU General Public License v3.0
414 stars 41 forks source link

Allow extending a serve handler by overriding the existing isProduction #425

Closed jpwilliams closed 7 months ago

jpwilliams commented 9 months ago

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.

import { functions, inngest } from "@/inngest";
import { serve } from "inngest/next";

export default serve({
  client: inngest,
  functions,
  // set a static value
  isProduction: false,
});
import { functions, inngest } from "@/inngest";
import { serve } from "inngest/next";

export default serve({
  client: inngest,
  functions,
  // or use an environment variable check
  isProduction: process.env.MY_CUSTOM_VAR === "yes",
});
import { functions, inngest } from "@/inngest";
import { serve } from "inngest/next";

export default serve({
  client: inngest,
  functions,
  // or use a function to calculate the value dynamically
  isProduction: async () => {
    const amIProd = await makeRequestToCheck();
    return amIProd;
  },
});

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

changeset-bot[bot] commented 9 months ago

⚠️ No Changeset found

Latest commit: caf03164f7c093e0efd87f782f03efc18923615d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

inngest-release-bot commented 9 months ago

A user has added the prerelease/inngest label, so this PR will be published to npm with the tag pr-425. It will be updated with the latest changes as you push commits to this PR.

You can install this prerelease version with:

npm install inngest@pr-425

The last release was built and published from caf03164f7c093e0efd87f782f03efc18923615d.

IGassmann commented 7 months ago

@jpwilliams, a user tried this feature and experienced some issues. Linking the conversation..

jpwilliams commented 7 months ago

Thanks, @IGassmann.

Closing this now. Superseded by #488.