Skip to content

Commit a81aacb

Browse files
feat(env): env variable names are prefixed with JANE_
Merge pull request #3 from janetechinc/francesco/jane-env-variables
2 parents 9eb6d42 + 4c47d5a commit a81aacb

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ The files will be compiled under `dist` directory:
2626
```bash
2727
npm test
2828
```
29+
30+
## Configuration
31+
32+
Set the following environment variables:
33+
34+
```bash
35+
export JANE_CLIENT_ID="<provided by partner success>"
36+
export JANE_CLIENT_SECRET="<provided by partner success>"
37+
# optional, defaults to the following
38+
export JANE_API_URL="https://api.iheartjane.com"
39+
```

examples/javascript/src/lib/api-service.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { request } from './http.mjs'
22
import { URL } from "url";
33

44
const headers = { 'Content-Type': 'application/json' }
5+
const defaultHost = "https://api.iheartjane.com"
56

67
const authenticateClient = async () => {
7-
const clientId = process.env.CLIENT_ID || ''
8-
const clientSecret = process.env.CLIENT_SECRET || ''
9-
const janeApiHost = process.env.JANE_API_HOST
8+
const clientId = process.env.JANE_CLIENT_ID || ''
9+
const clientSecret = process.env.JANE_CLIENT_SECRET || ''
10+
const apiUrl = process.env.JANE_API_URL
1011

1112
const resp = await request({
1213
method: 'post',
13-
url: `${janeApiHost}/oauth/token`,
14+
url: `${apiUrl}/oauth/token`,
1415
grant_type: 'client_credentials'
1516
}, {
1617
auth: {
@@ -23,14 +24,13 @@ const authenticateClient = async () => {
2324
}
2425

2526
const makeRequest = async (options) => {
27+
const apiUrl = process.env.JANE_API_URL
2628

27-
const host = process.env.API_HOST
28-
29-
if (!host) {
30-
throw Error('No API_HOST configured')
29+
if (!apiUrl) {
30+
throw Error('No JANE_API_URL configured')
3131
}
3232

33-
const url = new URL(options.path, host);
33+
const url = new URL(options.path, apiUrl);
3434

3535
try {
3636
const response = await request({

examples/javascript/src/lib/api-service.spec.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ describe('api service', () => {
1616
)
1717
})
1818

19-
describe('if no API_HOST is set', () => {
19+
describe('if no JANE_API_URL is set', () => {
2020
test('it throws an error', async () => {
2121
const token = 'someToken'
2222

2323
await expect(async () => {
2424
await apiService.post('/api/path', {}, token)
25-
}).rejects.toEqual(new Error('No API_HOST configured'))
25+
}).rejects.toEqual(new Error('No JANE_API_URL configured'))
2626
})
2727
})
2828

2929
describe('#get', () => {
3030
beforeEach(() => {
31-
process.env.API_HOST = 'https://test.localhost'
31+
process.env.JANE_API_URL = 'https://test.localhost'
3232
})
3333

3434
test('it calls fetch with method "get"', async () => {
@@ -61,7 +61,7 @@ describe('api service', () => {
6161

6262
describe('#post', () => {
6363
beforeEach(() => {
64-
process.env.API_HOST = 'https://test.localhost'
64+
process.env.JANE_API_URL = 'https://test.localhost'
6565
})
6666

6767
test('it calls fetch with method "post" and body data', async () => {

0 commit comments

Comments
 (0)