简体   繁体   中英

How to deploy react app to shared hosting thats running nodeJS?

I have been googling all over the place and couldn't find an answer that matches my current knowledge, so I hope someone can educate me a bit on this matter.

I made an React SPA through the create-react-app command. Now I want to deploy this to a hosting. My friend has a reseller hosting with cpanel, and the hosting company told me they have nodeJS enabled.

I tried building it and then simply copy-pasting it, but then the routing doesn't work. I read stuff about the server needing to run the javascript on server side and then I read about NodeJS and Express. But after this I am just getting more and more confused.

At first I thought express is something like a local server which you upload with all your files, but then I see command lines about running it on the server and such. So I am completely at a blank at this point.

How am I supposed to deploy my react app to a hosting (that has nodeJS enabled)?

I will keep this post close by, so I will respond almost directly. Feel free to ask anything, cause I can understand that the given information might be lacking. But I don't know what information I should be giving, so I will do this on demand.

Ok, so I tried going back to zero and just googled 'routing broken' and someone posted something that I tried. And it worked.

Apparently I had to add this to the .htaccess and the react app worked as expected. No fancy nodeJS things, just plain old htacces.

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

oh I had to add a homepage to the json package.

I think the confusion, and that whole story I typed, is due to me being confused by all these different kinds of answers to different kind of problems. Because of this I didn't know where to look. This did however gave me some clarification about 1 thing: I am confused how the web and NodeJS functions.

If anyone here can contribute to this discussion, I made a post about this subject.

Here: https://dev.to/beardedhippo/can-someone-educate-me-on-the-way-requests-work-with-nodejs-express-and-whatnot-51ik

Thank you for clicking and viewing!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM