Skip to content

fix(gateway): allow custom proxyFactory to use non-default proxyTypes #96

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

Conversation

Vincentdevreede
Copy link
Contributor

This PR improves flexibility in the gateway by allowing custom proxyFactory implementations to define and use custom proxyType values without triggering an "Unsupported proxy type" error.

Changes

  • Wrapped opts.proxyFactory with a fallback to defaultProxyFactory only if it returns undefined
  • Skip proxyType validation when a custom proxyFactory is provided
  • Default missing proxy hooks to NOOP functions

Previously, providing a custom proxyFactory and proxyType would still result in an error unless the type was listed in the internal PROXY_TYPES list. This fix ensures full control when extending proxy behavior through configuration.

// ——————————————————————————
// 1) “Normal” mode: return undefined to fall back
// ——————————————————————————
gateway({
  proxyFactory: (ctx) => {
    const { proxyType, opts, route } = ctx;

    if (proxyType === 'custom') {
      return myCustomProxy;
    }

    // returning undefined ⇒ defaultProxyFactory will be used
  }
});

// ——————————————————————————
// 2) “Disable fallback” mode: return null to opt out
// ——————————————————————————
gateway({
  proxyFactory: (ctx) => {
    const { proxyType, opts, route } = ctx;

    if (proxyType === 'custom') {
      return myCustomProxy;
    }

    // returning null ⇒ no fallback
    return null;
  }
});

- Skip proxyType validation when a custom proxyFactory is provided
- Fallback to defaultProxyFactory only if custom one returns undefined
- Default missing proxy hooks to NOOP functions
Copy link
Collaborator

@jkyberneees jkyberneees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Vincentdevreede many thanks for supporting the library evolution. I definitively like the proposal and makes total sense.

Could you please fix linting issues and extend the docs to reflect your proposal? Afterwards I will proceed with merging it.

@jkyberneees jkyberneees merged commit c74a187 into BackendStack21:master May 10, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants