Skip to content

Commit cdabb44

Browse files
authored
Use http in fetchFromAPI when host is 127.0.0.1 (#60)
* Use http in fetchFromAPI when host is 127.0.0.1 * Fix fetchFromAPI running in browser
1 parent e62910b commit cdabb44

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-storefront",
3-
"version": "7.7.1",
3+
"version": "7.7.2",
44
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
55
"module": "./index.js",
66
"license": "Apache-2.0",

src/props/fetchFromAPI.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ import fetch from '../fetch'
2525
*/
2626
export default function fetchFromAPI({ req, asPath, pathname }) {
2727
const host = req ? process.env.API_HOST || req.headers['host'] : ''
28-
const protocol = req ? (host.startsWith('localhost') ? 'http://' : 'https://') : ''
2928
const [path, search] = asPath.split('?')
3029

30+
let protocol = ''
31+
32+
if (req) {
33+
protocol = 'https://'
34+
35+
if (host.startsWith('localhost') || host === '127.0.0.1') {
36+
protocol = 'http://'
37+
}
38+
}
39+
3140
let uri = `/api${path.replace(/\/$/, '')}`
3241

3342
if (search) {

0 commit comments

Comments
 (0)