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

Expose Request Method in requestConfig for Middleware #86

Closed
fco-fbatch opened this issue Aug 30, 2024 · 1 comment · Fixed by #87
Closed

Expose Request Method in requestConfig for Middleware #86

fco-fbatch opened this issue Aug 30, 2024 · 1 comment · Fixed by #87
Labels
enhancement New feature or request

Comments

@fco-fbatch
Copy link

Description:

I would like to propose an enhancement to the fal.config method where a requestMiddleware function can be further configured. Currently, the requestConfig object only exposes the headers and URL information. However, it would be beneficial if the requestConfig also exposed the HTTP request method.

Use Case:

In our use case, we need to supply an API auth token to the FAL proxy server through the middleware. Here’s a basic example of how we configure the client:

fal.config({
  proxyUrl: "http://localhost:8080/api/fal/proxy",
  requestMiddleware: (requestConfig) => {
    return Promise.resolve({
      ...requestConfig,
      headers: {
        ...requestConfig.headers,
        "x-my-bearer": `Bearer ${bearer}`,
        "x-my-content-id": contentId,
      },
    });
  },
});

This middleware adds authentication tokens to the request headers. However, to enhance security, it would be ideal to omit sending tokens in GET requests, lowering exposure.

Proposed Enhancement:

Consider exposing the request method in the requestConfig object passed to the requestMiddleware. This additional information would allow developers to conditionally include or exclude sensitive headers based on the request method, reducing the risk of exposing secrets in scenarios where they are not needed.

Example Usage:

fal.config({
  proxyUrl: "http://localhost:8080/api/fal/proxy",
  requestMiddleware: (requestConfig) => {
    if (requestConfig.method === 'POST') {
      return Promise.resolve({
        ...requestConfig,
        headers: {
          ...requestConfig.headers,
          "x-my-bearer": `Bearer ${bearer}`,
          "x-my-content-id": contentId,
        },
      });
    } else {
      return Promise.resolve(requestConfig);
    }
  },
});
@drochetti
Copy link
Collaborator

Hey @fco-fbatch, thanks for the thoughtful feature request. I opened a PR for this: #87

@drochetti drochetti linked a pull request Sep 5, 2024 that will close this issue
@drochetti drochetti added the enhancement New feature or request label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants