pserv/react-app/README.first
2018-04-29 18:11:45 -04:00

44 lines
1.6 KiB
Plaintext

This directory contains an example of an React application that can interact
with your server.
To use it, you have to add a small feature to your server called HTML5 fallback,
which is the ability to serve /index.html if it cannot find a file at the path
specified.
See https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment
for more details.
For our server, you have to implement this by making the appropriate
changes to how you serve static assets.
An update to the base code sets up the -a switch to activate this behavior:
https://git.cs.vt.edu/cs3214-staff/pserv/commit/65ee63d43ef92553cd3650b3e276d71e2f7daec5
(Note that the patch doesn't contain the necessary fixes to handle_static_assets
which will be part of future versions of this project.)
The necessary improvement can be made by substituting /index.html as the fname
when the call to access() fails instead of returning 404. However, for paths
denoting / or existing directories, you must also serve /index.html, which requires
a second check to see whether there is an existing directory (and serve /index.html
if so).
Once you've made this addition, you can test the app as follows:
(1) ssh into rlogin with
$ ssh -L 10000:localhost:yourport you@rlogin.cs.vt.edu
(2) Add node to your PATH:
$ export PATH=/home/courses/cs3214/software/node-v8.11.1-linux-x64/bin:$PATH
(3) Inside react-app, run
$ npm run build
(4) and then run your server with
$ ./server -p yourport -a -R ../react-app/build
(5) You should now be able to go to the app in http://localhost:10000/