- Build a React Application
- Deploy the application to a web server
- Open a
command prompt
(Windows) orterminal
(Mac). - Change the current directory to
working\keeptrack
. - Run the following command to install the node.js web server named
serve
:npm install -g serve
- Run one of the following commands:
npm run build
yarn build
- After the buld finishes, verify a
keeptrack\build
directory was created.
-
In the
command prompt
(Windows) orterminal
(Mac) run the following command to start a web server and serve up the contents of thebuild
directory created in the last step.serve build
Assuming you would like to serve a state site, single page application or just a static file (no matter if on your device or on the local network), the package
serve
is a web server that serves static content.It behaves exactly like static deployments on https://vercel.com so it's perfect for developing your static project.
For more information see: https://www.npmjs.com/package/serve
-
The output should be as follows.
Serving! ... Copied local address to clipboard!
-
Open a new browser tab and paste the local link copied to the clipboard in the last step into the address bar.
-
You should see the application running in your browser.
-
Click on Projects in the **navigation menu **on the top of the page and the list of projects should be displayed.
If you see the following error message displayed your backend is likely shut down. Run the command
npm run api
to restart the backend. -
After navigating to the projects route, refresh your browser.
-
You should see a 404 error page.
-
Use
Ctrl+C
to stop the web server. -
Start the web server again but add the
-s
flag for single-page-application.serve -s build
-
Follow these steps to verify the server is now redirecting to
index.html
when it can't find a route.- Visit the root of the site
http://localhost:5000/
- Click on Projects in the **navigation menu **on the top of the page and the list of projects should be displayed.
- After navigating to the projects route, refresh your browser.
- You should see the projects page refresh and display the projects.
Note that you are no longer getting the 404 error page.
- Visit the root of the site
If time permits you can read the documentation linked below for very similar steps to deploy the application on common production web servers and cloud platforms including AWS, Azure, Heroku, Netlify, and Vercel.