codexstanford / codex-insurance-fullstack

0 stars 0 forks source link

Get it running

Local

Prerequisites

Node.js and pnpm must be installed. This project uses pnpm's workspace feature for the monorepo structure.

Commands

  1. Run pnpm install in the project directory.
  2. If there is no db.sqlite file in ./var, create it by running pnpm db:push.
  3. Create a .env file with the required environmental variables. This file is gitignored for security reasons. You can either obtain it securely from someone who has it on his or her machine or create a new one by copying ./.env.blueprint and renaming it to .env.
  4. Run pnpm dev to start the development server. It will watch for file changes and rebuild the app. Note that this is only a development server and may lack some production functionality.

Setting Up AWS EC2

Preparation

  1. Place the .pem key file in the project root and rename it to ssh-key.pem (this file is gitignored).
  2. Run pnpm ssh:connect on a UNIX machine to connect to the server.
  3. Follow these instructions to install Node.js on the server.
  4. Install pnpm: curl -fsSL https://get.pnpm.io/install.sh | sh -.
  5. Install pm2: pnpm install pm2 -g.

This setup would already allow you to upload code via SSH, perform the steps form the local section above via SSH, and run the server using pm2. To automate this, see below how to set up continuous integration.

Continuous Integration

  1. Add the key as a repository secret on this GitHub page, naming it SSH_PRIVATE_KEY.
  2. Push a commit to the main branch to trigger the action defined in .github/workflows/deploy-ec2.yaml, which will build and transfer the app to EC2.
  3. The project files are on the server now. Do step 2. and 3. of the local section above via SSH on the server. For step 3, you can use echo "[paste env content here] > .env"..
  4. Start the Node.js server from the SSH terminal: NODE_ENV=production pm2 start ~/codex-insurance-fullstack/process.json. Use pm2 status to check status, and pm2 logs to see logs.

Serving on port 80

The Node server runs on port 3000 by default. To serve on the standard HTTP port 80, running the Node server as a superuser is required. However, this is considered a security risk. A more secure approach is to use a reverse proxy.

To securely serve the Node app on port 80, you need to install Nginx on the server. Nginx will listen on port 80 and forward all requests to your Node app running on port 3000. Follow this tutorial for detailed instructions: How to run a Node.js server with Nginx.

If the sites-available and sites-enabled folders do not exist, create them. If the Nginx restart command doesn't work, try the following commands:

sudo pkill -f nginx & wait $!
sudo systemctl start nginx

Constraints

Misc

Known bugs