Skip to content

Commit 45a429a

Browse files
refactor: origin check and allow origin skipping
close #61
1 parent 6407b0b commit 45a429a

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/allowed-origins.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
"https://nmrxiv.org",
3+
"http://nmrxiv.org",
4+
"http://localhost",
5+
"http://localhost:3000",
6+
"http://127.0.0.1:",
7+
"http://127.0.0.1:3000",
8+
"http://test.nmrxiv.org",
9+
"http://193.196.39.168",
10+
"http://193.196.39.168:3000",
11+
"https://nodejsdev.nmrxiv.org"
12+
]

src/events/event.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
import { EventType, EventData } from './types';
2-
3-
const ALLOWED_ORIGINS: string[] = [
4-
'https://nmrxiv.org',
5-
'http://nmrxiv.org',
6-
'http://localhost',
7-
'http://localhost:3000',
8-
'http://127.0.0.1:',
9-
'http://127.0.0.1:3000',
10-
'http://test.nmrxiv.org',
11-
'http://193.196.39.168',
12-
'http://193.196.39.168:3000',
13-
'https://nodejsdev.nmrxiv.org',
14-
];
2+
import ALLOWED_ORIGINS from '../allowed-origins.json';
153

164
const namespace = 'nmr-wrapper';
175

@@ -32,7 +20,10 @@ function on<T extends EventType>(
3220

3321
const url = new URL(origin);
3422

35-
if (!ALLOWED_ORIGINS.includes(url.origin)) {
23+
const skipOriginCheck =
24+
ALLOWED_ORIGINS.length === 0 || ALLOWED_ORIGINS.includes('*');
25+
26+
if (!skipOriginCheck && !ALLOWED_ORIGINS.includes(url.origin)) {
3627
throw new Error(`Invalid Origin ${origin}`);
3728
}
3829

0 commit comments

Comments
 (0)