xboxman555
xboxman5552y ago

React and Fetch Api; Returning reacts index.html File instead of api endpoint?

My Fetch Api with react is returning index.html instead of its data is there something with react I need to change? ``` fetch() .then((response) => response.json()) .then((data) => console.log(data))
fetch() .then((response) => response.text()) .then((data) => console.log(data))
Solution:
do you not have https:// on either of them?
Jump to solution
14 Replies
xboxman555
xboxman555OP2y ago
this code is inside of a component
ghardin137
ghardin1372y ago
is it exactly that code?
xboxman555
xboxman555OP2y ago
yeah its bringing back my index.html
ghardin137
ghardin1372y ago
well you haven't given fetch() a url, so it's using the existing one or anything else for that matter
xboxman555
xboxman555OP2y ago
i have one, got rid of it for posting it
ghardin137
ghardin1372y ago
that's why i asked if it was exactly that code what url is there?
xboxman555
xboxman555OP2y ago
open weather api and a time api
ghardin137
ghardin1372y ago
can you post the actual url, you can remove any api keys or anything
xboxman555
xboxman555OP2y ago
www.timeapi.io/api/Time/current/zone?timeZone=America/New_York api.openweathermap.org/data/2.5/weather?lat=32.779167&lon=-96.808891&appid=... it has other things such as export default function stuff you would find in a component too i found something with proxy in package.json, maybe that got something to do with it @ghardin137 u there?
Solution
ghardin137
ghardin1372y ago
do you not have https:// on either of them?
xboxman555
xboxman555OP2y ago
no
ghardin137
ghardin1372y ago
thats why you need that
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View