提取返回我自己的index.html的html源 [英] Fetch returns html source of the my own index.html

查看:81
本文介绍了提取返回我自己的index.html的html源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在react-create-app服务器(localhost:3000)中使用fetch从我的apache(localhost:80)获取静态.json文件,但是它返回我的react index.html文件的源!

I am trying to use fetch in an react-create-app server(localhost:3000) to get a static .json file from my apache(localhost:80) but it returns source of my react index.html file!

指定端口号会导致网络错误"

Specifying port number results in "networking error"

const that=this;
fetch("localhost/myapp/data/structure.json").then((res)=> {return res.text()})
                .then(((data)=>{that.setState({structure: data})})).catch((e)=>{alert(e.toString())});

推荐答案

从根本上说,问题在于使react-create-app与本地服务器一起使用,本指南 https://daveceddia.com/create-react-app-express-backend/

Downright the problem comes to making react-create-app work with a local server which is explained in this guide https://daveceddia.com/create-react-app-express-backend/

简而言之,我需要在我的package.json中放置一个代理属性,其值等于本地服务器的地址.就我而言:

In short I needed to put a proxy property with the value equal to address of my local server in my package.json. In my case:

  "proxy": "http://localhost:80"

这篇关于提取返回我自己的index.html的html源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆