@heroku/heroku-fetch 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/client/service-configurations.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,10 @@ const euDataClient = new HerokuApiClient({
|
|
|
62
62
|
token: 'your_token',
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
// The data client's host comes from HEROKU_DATA_HOST, then
|
|
66
|
+
// HEROKU_POSTGRESQL_HOST, then postgres-api.heroku.com. A bare hostname
|
|
67
|
+
// gets https://. An explicit baseUrl or region takes precedence.
|
|
68
|
+
|
|
65
69
|
// Particleboard
|
|
66
70
|
const particleboardClient = new HerokuApiClient({
|
|
67
71
|
service: 'particleboard',
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
const HEROKU_V3_ACCEPT = 'application/vnd.heroku+json; version=3';
|
|
2
|
+
/**
|
|
3
|
+
* The data API base URL: `HEROKU_DATA_HOST`, then `HEROKU_POSTGRESQL_HOST`,
|
|
4
|
+
* then `https://postgres-api.heroku.com`. These are the variables the Heroku
|
|
5
|
+
* CLI has long honored for the data API. A bare hostname gets `https://`; a
|
|
6
|
+
* value with an `http://` or `https://` scheme, in any case, is used as-is. `process` is guarded for browser builds.
|
|
7
|
+
*/
|
|
8
|
+
function dataBaseUrl() {
|
|
9
|
+
const env = typeof process === 'undefined' ? undefined : process.env;
|
|
10
|
+
const host = env?.HEROKU_DATA_HOST || env?.HEROKU_POSTGRESQL_HOST;
|
|
11
|
+
if (!host)
|
|
12
|
+
return 'https://postgres-api.heroku.com';
|
|
13
|
+
return /^https?:\/\//i.test(host) ? host : `https://${host}`;
|
|
14
|
+
}
|
|
2
15
|
export const SERVICE_CONFIGS = {
|
|
3
16
|
custom: {
|
|
4
17
|
// Must be provided by user; no Accept default — the URL may be
|
|
@@ -7,7 +20,10 @@ export const SERVICE_CONFIGS = {
|
|
|
7
20
|
baseUrl: '',
|
|
8
21
|
},
|
|
9
22
|
data: {
|
|
10
|
-
|
|
23
|
+
// A getter so the environment is read when each client is built, not at import.
|
|
24
|
+
get baseUrl() {
|
|
25
|
+
return dataBaseUrl();
|
|
26
|
+
},
|
|
11
27
|
defaultAccept: HEROKU_V3_ACCEPT,
|
|
12
28
|
},
|
|
13
29
|
particleboard: {
|