Skip to content

Commit

Permalink
Use http in fetchFromAPI when host is 127.0.0.1 (#60)
Browse files Browse the repository at this point in the history
* Use http in fetchFromAPI when host is 127.0.0.1

* Fix fetchFromAPI running in browser
  • Loading branch information
markbrocato authored Mar 10, 2020
1 parent e62910b commit cdabb44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-storefront",
"version": "7.7.1",
"version": "7.7.2",
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
"module": "./index.js",
"license": "Apache-2.0",
Expand Down
11 changes: 10 additions & 1 deletion src/props/fetchFromAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ import fetch from '../fetch'
*/
export default function fetchFromAPI({ req, asPath, pathname }) {
const host = req ? process.env.API_HOST || req.headers['host'] : ''
const protocol = req ? (host.startsWith('localhost') ? 'http://' : 'https://') : ''
const [path, search] = asPath.split('?')

let protocol = ''

if (req) {
protocol = 'https://'

if (host.startsWith('localhost') || host === '127.0.0.1') {
protocol = 'http://'
}
}

let uri = `/api${path.replace(/\/$/, '')}`

if (search) {
Expand Down

0 comments on commit cdabb44

Please sign in to comment.