skip to Main Content

I want to host a react app on my godaddy server. I’m able to run webpack dev server locally, but I don’t know how to host it on my godaddy cpanel server.

Link to my code: https://bitbucket.org/touristtribe/tribe-frontend/src/master/

2

Answers


  1. First of all, why are you using jQuery with React? This is not recommended.

    You’ll first need to build your project.
    For Example, if you have yarn, simply execute yarn build in your terminal.
    It will return a build folder that includes an .html file and other folders/files.

    Then all you need to do is upload those files/folders to your host.

    Login or Signup to reply.
  2. In case you’re using create-react-app, you get a script to build your production app, npm run build

    This builds a folder with all the necessary html,css and js files called build. But when you’re hosting in an apache server, you’ll always need a .htaccess file. So first create this file in the public folder and then run the build command. The code that goes in the .htaccess file is

    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]

    Moreover, if you’re deploying to any subdirectory, you’ll have to specify that in the package.json file as:
    "homepage": "http://mywebsite.com/relativepath"

    You can read more in this blog.

    Note: This answer might only help if you’re using create-react-app.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search