Skip to content

Commit f812a53

Browse files
authored
Merge pull request #248 from JackBailey/local-ip
Add support for 127.0.0.1 alongside localhost when getting relative URLs
2 parents 1751f24 + b7c7095 commit f812a53

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

app/client/src/common/utils.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react'
22

3+
let isLocalhost = (window.location.hostname.indexOf('localhost') >= 0 || window.location.hostname.indexOf('127.0.0.1') >= 0) && window.location.port !== '';
34
export const getServedBy = () => {
4-
return (window.location.hostname.indexOf('localhost') >= 0 && window.location.port !== '')
5+
return isLocalhost
56
? 'flask'
67
: 'nginx'
78
}
89

910
export const getUrl = () => {
1011
const portWithColon = window.location.port ? `:${window.location.port}` : ''
11-
return (window.location.hostname.indexOf('localhost') >= 0 && window.location.port !== '')
12-
? `http://localhost:${process.env.REACT_APP_SERVER_PORT || window.location.port}`
12+
return isLocalhost
13+
? `http://${window.location.hostname}:${process.env.REACT_APP_SERVER_PORT || window.location.port}`
1314
: `${window.location.protocol}//${window.location.hostname}${portWithColon}`
1415
}
1516

@@ -19,8 +20,8 @@ export const getPublicWatchUrl = () => {
1920
return `${shareableLinkDomain}/w/`
2021
}
2122
const portWithColon = window.location.port ? `:${window.location.port}` : ''
22-
return (window.location.hostname.indexOf('localhost') >= 0 && window.location.port !== '')
23-
? `http://localhost:${process.env.REACT_APP_SERVER_PORT || window.location.port}/#/w/`
23+
return isLocalhost
24+
? `http://${window.location.hostname}:${process.env.REACT_APP_SERVER_PORT || window.location.port}/#/w/`
2425
: `${window.location.protocol}//${window.location.hostname}${portWithColon}/w/`
2526
}
2627

0 commit comments

Comments
 (0)