External/Internal Sites on T7 & CWBI
You've done a lot of working with npm run dev and now you're ready to get your site off your local workstation so others can see it!
This is a guide on how you might go about doing that. (Let me know in the comments if it needs tweaks/clarification!)
Background
If you are using React + Vite you cannot just paste the source jsx files onto a webserver/T7. You must first build the webapp. This takes those jsx files and transpiles them into 1 JS file and 1 CSS file*. It then places these in a dist directory when you run npm run build.
Then contents of this build directory are what you copy to your T7.
For the cloud this is a bit different. When you commit to github an action in your .github/workflows/*.yml would run and using this github action it would transpile and bundle your files like above and then this action uses AWS CLI to copy the files to S3 where your dev, test, or prod site are deployed. (Depending on the action file)
But now you know you can run npm run build to get this directory with your distribution files in it. How do you move those around to the various places? I mentioned that CWBI/cloud is done via that CI/CD github action. But what about the T7?
T7 React/App files for web
To get static web files (Html/css/js) to your T7 webserver you have a few options. It's worth mentioning that this process is NOT the same for cloud and this is really just to let you (the developer) take advantage of your local webserver you already have in the interim! Perhaps to provide local water management and internal CORPS members a means of testing your internal webapp?
The tried and true method is to use WinSCP. But after a while you will find with every iteration having to
- npm run build
- Login to WinSCP
- Remove the files from the last run in the
assets directory - Copy the new files over to the directory
This is very tedious!
Instead I recommend that you edit the package.json in the root of your directory (this gets created after you run the setup steps for Groundwork)
And add these lines:
(Replace the scripts key/value in the file with this)
TAKE CARE
swt and make sure you WANT to deploy into the root of htdocs as opposed to say htdocs/swt THIS will overwrite files in a given directory. These scripts (key/red) will be the npm run dev (which calls the vite command below). So you can make more of these and chain them. This is effectively calling command prompt for you!
With the putty profile below, you'll be able to run
npm run deploy-all to push public directory and ALL files
and
npm run deploy to move only the js, html, and css files for smaller pushes!
Credentials?
You'll notice above I have a -load for the plink command. This loads a putty profile I have named CWPT7.
Few things for the profile - this is critical to avoid using a password each time!
Generate a key
- Install putty through app portal
- Set a keypair by making a key using
puttygen(Generate and wiggle mouse!) - Copy the upper contents PUBLIC KEY!!! of puttygen after it generates and paste this into your CWP user
~/.ssh/authorized_keys(MAKE A BACKUP OF THIS FIRST IF YOU ARE UNCERTAIN) i.e.cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak - Save the
privatekey locallyDO NOT SHARE PRIVATE KEY
(DO NOT COPY
private keyTO ANY SERVER!) This should be made PER USER and each user's public key placed in the authorized_keys file. DO NOT SHARE PRIVATE KEY WITH ANYONE.
Setup the putty profile
- Open
putty.exe - Name your session
CWPT7 - Type your T7 IP address for the CWP zone under Host Name (or IP Address)
- Click Credentials under Connection > SSH > Auth and Browse to your private key you saved on step # 4 above.
5. Click Data under Connection and enter your CWP user name. I.e. for SWT that's m5cwpa51
Click Session at the top of the side menu and click Save to ensure these changes persist.
You are now ready to use your putty profile! Test it in windows command prompt with: plink -batch -load CWPT7 whoami
should return your cwp production zone username!
How does routing work for my react app on the T7?
While this is solved for you on the cloud site. It is not on the T7.
You will need to put a ticket in with G6. I recommend you search "CWMS Ticket" and assign it as NOT CRITICAL to the WEB TEAM.
Depending on where you want the site pushed to.
I.e. is this in the root of your htdocs or is this in a sub directory i.e. /htdocs/swt
G6 (normally Mark Carron) will be able to setup the clientside routing for you. The basic configuration for apache /htdocs is this:
<Directory "/wm/swt/wm_web/var/apache2/2.4/htdocs">
# If not already on
RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
You can see this is looking for a file or directory and if it does not exist it will rewrite the path to your index.html file at the root. The key piece is this block IS FOR THE ROOT OF THE WEBSERVER.
This allows React + Redux to handle client-side routing. I.e. javascript handles sub pages instead of you having multiple index.html files you now have one. A single page application (SPA)
COOP?
SWT has a nighly rsync task that copies all web files to our coop!
`15 0 * * * /wm/swt/localsoft/cwms/bin/cwmsenv /wm/swt/##cwpuser##/bin/syncCoopWeb.sh >/dev/null 2>&1`This file /wm/swt/m5cwpa51/bin/syncCoopWeb.sh contains:
/wm/swt/cwpuser/config/rsync_exclude.txt
/wm/swt/wm_web/var/apache2/2.4/htdocs/videos /wm/swt/wm_web/var/apache2/2.4/htdocs/webdata/dcptxsum /wm/swt/wm_web/var/apache2/2.4/htdocs/webdata/gagedata
TDL-CESWF-EC-H-National Web Development


