Skip to content

Commit 46a3ff5

Browse files
committed
refactor: origins are optional
1 parent 7536f6d commit 46a3ff5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ mql('https://microlink.io', {
3333

3434
## Environment Variables
3535

36-
### ORIGINS
36+
### API_KEY
3737

3838
*Required*</br>
39-
Type: `string`|`string[]`
39+
Type: `string`
4040

41-
The list of allowed domains authorized to consume your Microlink API credentials.
41+
Your Microlink API key used to [authenticate](https://microlink.io/docs/api/api-basics/authentication) your requests.
4242

43-
Note domains should be provided in the [URL.origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) format (e.g., `'https://example.com'`).
43+
### ORIGINS
4444

45-
### API_KEY
45+
Type: `string`|`string[]`
4646

47-
*Required*</br>
48-
Type: `string`
47+
The list of allowed domains authorized to consume your Microlink API credentials.
4948

50-
Your Microlink API key used to [authenticate](https://microlink.io/docs/api/api-basics/authentication) your requests.
49+
Note domains should be provided in the [URL.origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) format (e.g., `'https://example.com'`).
5150

5251
### API_ENDPOINT
5352

pages/api/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const API_KEY = process.env.API_KEY
1111
const origins = process.env.ORIGINS.split(',').map(n => n.trim())
1212
const isProduction = NODE_ENV === 'production'
1313

14-
const isAllowedDomain = isProduction
15-
? origin => origins.includes(origin)
16-
: () => true
14+
const isAllowedDomain =
15+
isProduction && origins.length > 0
16+
? origin => origins.includes(origin)
17+
: () => true
1718

1819
export default async request => {
1920
const url = request.nextUrl

0 commit comments

Comments
 (0)