Search code examples
node.jsreactjssequelize.jscpanel

Deploy React on Cpanel => Cannot GET /


I need help to install my react project with Cpanel (O2switch host). See my project :

enter image description here

For my server I use Sequelize to manage ma data base.

I followed steps provids on the web :

Step 0 : Create the database (if you need it).

Step 1 : Add into package.json, contains into my client file, the following code : "homepage": ".",

enter image description here

Step 2 : npm run build into my client file to create build file (in red into the previous picture).

Step 3 : Make a .htaccess it will look like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

Step 4 : Create my nodeJS server on Cpanel

enter image description here

Step 5 : Go inside my Cpanel > file directory > monGouvernement :

enter image description here

And add into public all files from my build file. After, add all files from my server file as below (without node_modules file) :

enter image description here

Step 6 : Go back to my nodeJs_setup to click on "Run NPM install" to install dependencies and create node_modules files.

At this step, my database is created. But my front-end doesn't work. See what my browser show me:

enter image description here

I don't understand the reason of it. Could help me to solve this issus please ?


Solution

  • Ok I solved my problem.

    The answer is : I didn't add my build file at the right place. On my O2Switch Cpanel I'm hosting my domaine name and my nodeJs server (that I created with the setup_NodeJs_app). So, I got two files in my file manager :

    enter image description here

    The first one is for my domaine name. The second one is for my nodeJs server.

    So I have to add my build file into my domaine (mon-gouvernement.fr) name like this :

    enter image description here

    And my server files into the other one (monGouvernement) :

    enter image description here

    Like this, everything work perfectly.