Search code examples
reactjsbuildweb-deployment

How to serve react app on server with sub-directory homepage on an existing domain?


I am new to webdev. I want to deploy a react-app on our lab's server. i want other lab members to access this app with https://ourlab.org:PORT_NUM/myApp

On the lab server by sshing to it: under my home directory, i have this myApp folder. I give package.json this "homepage":"https://ourlab.org/myApp" field and then run npm run build, and then run npx serve -s build

it gives me

| Serving! │

│ - Local: http://localhost:5000 │

│ - On Your Network: http://159.89.xxx.xxx:5000 |

I expect I could access the app at url https://ourlab.org:5000/myApp on my local computer. But my browser does not get response.

BTW could someone please explain how this "homepage" works with more details?


Solution

  • when you run serve, you are serving the app from your local computer. If you want to serve the app from your lab-server find the document root on that server, create there a directory "myApp" and copy the content of the build directory from your computer into that directory on your lab server.

    The build directory is the result of running ´npm run build´ assuming you have created your app with create-react-app.