fix: Fix setApiKey and setTwilioEmailAuth to prevent overwriting baseUrl by Be3751 · Pull Request #1386 · sendgrid/sendgrid-nodejs
Fixes
If you use setDefaultRequest to change baseUrl to a custom value, and execute setDefaultRequest before setApiKey, the baseUrl that you thought you had changed to a custom value will be overwritten with SENDGRID_BASE_URL.
For example, if you want to send a request to a mock SendGrid prepared in a local environment, you need to be careful about the execution order of setApiKey and setDefaultRequest as follows.
// You must execute setApiKey first. const client = new Client(); client.setApiKey('SG.xxxxx'); client.setDefaultRequest('baseUrl', 'localhost:3030');
In order to resolve it, I've decided to make the following changes, including setTwilioEmailAuth, which has a similar dependency:
- Do not execute
setDefaultRequest('baseUrl', SENDGRID_BASE_URL)insidesetApiKeysince the default value forbaseUrlisSENDGRID_BASE_URL. - Execute
setDefaultRequest('baseUrl', TWILIO_BASE_URL)insidesetTwilioEmailAuthdepending on whetherbaseUrlhas been updated to a custom value.
Checklist
- I acknowledge that all my contributions will be made under the project's license
- I have made a material change to the repo (functionality, testing, spelling, grammar)
- I have read the Contribution Guidelines and my PR follows them
- I have titled the PR appropriately
- I have updated my branch with the main branch
- I have added tests that prove my fix is effective or that my feature works
- I have added the necessary documentation about the functionality in the appropriate .md file
- I have added inline documentation to the code I modified
If you have questions, please file a support ticket.