Skip to content

Commit 319754e

Browse files
committed
review comments
1 parent b356716 commit 319754e

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

docs/use-cases/data-residency-set-hostname.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Choosing a hostname to send messages to
1+
# Choosing a data-residency to send messages to
22

33
Use the `setDataResidency` setter to specify which host to send to:
44

5-
Send to EU (hostname: `https://api.eu.sendgrid.com/`)
5+
Send to EU (data-residency: `https://api.eu.sendgrid.com/`)
66
```js
77
const sgMail = require('@sendgrid/mail');
88
sgMail.setDataResidency('eu');
@@ -16,7 +16,7 @@ const msg = {
1616
sgMail.send(msg);
1717
```
1818
Send to Global region, this is also the default host, if the setter is not used
19-
(hostname: `https://api.sendgrid.com/`)
19+
(data-residency: `https://api.sendgrid.com/`)
2020
```js
2121
const sgMail = require('@sendgrid/mail');
2222
sgMail.setDataResidency('global');
@@ -32,7 +32,6 @@ sgMail.send(msg);
3232

3333
## Limitations
3434

35-
1. Setting the API Key (via `client.setApiKey()`) or Twilio Authentication (via `client.setTwilioEmailAuth()`) will override the hostname to default value. Use the setter call after this set-up.
36-
2. Emails can only be sent to two hosts for now; 'eu' (https://api.eu.sendgrid.com/) and 'global' (https://api.eu.sendgrid.com/)
37-
2. The default hostname is https://api.sendgrid.com/
35+
1. Emails can only be sent to two hosts for now; 'eu' (https://api.eu.sendgrid.com/) and 'global' (https://api.eu.sendgrid.com/)
36+
2. The default data-residency is https://api.sendgrid.com/
3837
3. The valid values for `region` in `client.setDataResidency(region)` are only `eu` and `global`. Case-sensitive.

packages/client/src/classes/client.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
const API_KEY_PREFIX = 'SG.';
1515
const SENDGRID_BASE_URL = 'https://api.sendgrid.com/';
1616
const TWILIO_BASE_URL = 'https://email.twilio.com/';
17-
17+
const SENDGRID_REGION = 'global';
1818
// Initialize the allowed regions and their corresponding hosts
1919
const REGION_HOST_MAP = {
2020
eu: 'https://api.eu.sendgrid.com/',
@@ -24,7 +24,7 @@ class Client {
2424
constructor() {
2525
this.auth = '';
2626
this.impersonateSubuser = '';
27-
this.sendgrid_region = '';
27+
this.sendgrid_region = SENDGRID_REGION;
2828

2929
this.defaultHeaders = {
3030
Accept: 'application/json',
@@ -44,10 +44,8 @@ class Client {
4444

4545
setApiKey(apiKey) {
4646
this.auth = 'Bearer ' + apiKey;
47-
// this means that region was never set before
48-
if (this.sendgrid_region == '') {
49-
this.setDefaultRequest('baseUrl', SENDGRID_BASE_URL);
50-
}
47+
this.setDefaultRequest('baseUrl', REGION_HOST_MAP[this.sendgrid_region]);
48+
5149
if (!this.isValidApiKey(apiKey)) {
5250
console.warn(`API key does not start with "${API_KEY_PREFIX}".`);
5351
}

0 commit comments

Comments
 (0)