PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] What should I use instead of localhost to deploy a React App?

 July 13, 2022     contact-form, localhost, reactjs, web-deployment     No comments   

Issue

Please, I have this piece of code for a Contact Form in a React APP. It works fine locally, but after I deploy it doesn't work. I guess I have change the localhost for something else, but for what?

Let's say that my domain is https://www.something.com. What should I use instead of localhost to deploy my React App?

Error message that I receive if I keep the localhost domain: NetworkError when attempting to fetch resource.

PS.: The website works perfectly as well (locally and after the deploy). What I am trying here is to receive an answer of my fetch method (for my contact form) that it's not working.

fetch('http://localhost:5500/contact', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json;charset=utf-8',   
  },
  body: JSON.stringify(details),
})

Solution

Whatever server backend you are running on port 5500 needs to be hosted online too. At the moment you just have your frontend hosted.

Once you have your backend hosted, change your fetch URL to that instead.



Answered By - blessedcoder
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing