File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { EventType , EventData } from './types' ;
2+ import { isIPAddress } from '../utilities/isIPAddress' ;
23
34const ALLOWED_ORIGINS : string [ ] = [
45 'https://nmrxiv.org' ,
56 'http://nmrxiv.org' ,
67 'http://localhost' ,
78 'http://localhost:3000' ,
9+ 'http://127.0.0.1:' ,
10+ 'http://127.0.0.1:3000' ,
811 'http://test.nmrxiv.org' ,
912 'http://193.196.39.168' ,
1013 'http://193.196.39.168:3000' ,
@@ -13,13 +16,17 @@ const ALLOWED_ORIGINS: string[] = [
1316const namespace = 'nmr-wrapper' ;
1417
1518function parseOrigin ( origin : string ) {
19+ let url : string | null = '' ;
1620 const urlSegments = origin . split ( '://' ) ;
17- const hostSegments = urlSegments [ 1 ] . split ( '.' ) ;
18- const startIndex = hostSegments . length > 2 ? 1 : 0 ;
19-
20- const url = `${ urlSegments [ 0 ] } ://${ hostSegments
21- . slice ( hostSegments . length > 1 ? startIndex : 0 )
22- . join ( '.' ) } `;
21+ if ( isIPAddress ( origin ) ) {
22+ url = origin ;
23+ } else {
24+ const hostSegments = urlSegments [ 1 ] . split ( '.' ) ;
25+ const startIndex = hostSegments . length > 2 ? 1 : 0 ;
26+ url = `${ urlSegments [ 0 ] } ://${ hostSegments
27+ . slice ( hostSegments . length > 1 ? startIndex : 0 )
28+ . join ( '.' ) } `;
29+ }
2330
2431 return url ;
2532}
Original file line number Diff line number Diff line change 1+ export function isIPAddress ( ip : string ) {
2+ return / (?: [ 0 - 9 ] { 1 , 3 } \. ) { 3 } [ 0 - 9 ] { 1 , 3 } / . test ( ip ) ;
3+ }
You can’t perform that action at this time.
0 commit comments