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

feat: Ability to modify headers and custom fetch implementation #269

Open
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

shahradelahi
Copy link

This PR introduces a new feature that allows users to modify fetch headers or use a custom fetch implementation. It uses nodejs/undici for making requests. According to the Node.js development team, the Undici module has better performance and compatibility.

Examples of Usages

Use an HTTP Proxy

Using a proxy is useful for those who are behind a corporate firewall and trying to reach out to the resend API server. Here is an implementation for custom fetch for using HTTPS proxy:

import { Resend } from 'resend';
import { fetch, ProxyAgent } from 'undici';
import 'dotenv/config';

if (!process.env.RESEND_API_KEY) {
  throw new Error('RESEND_API_KEY env is not defined');
}

const resend = new Resend(process.env.RESEND_API_KEY, {
  fetch: (input, init) => {
    return fetch(input, {
      ...init,
      dispatcher: new ProxyAgent('http://localhost:8080')
    });
  }
});

export default resend;

Please review this pull request and let me know if you have any feedback. Thank you!

@shahradelahi shahradelahi changed the title feat: Ability to Modify Fetch Headers or Use Custom Fetch Implementation feat: Ability to modify headers and custom fetch implementation Nov 19, 2023
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.

1 participant