The code for comunidades unidas internal website
This project uses Node + Express to interact with a MySQL Database and provide JSON APIs. The frontend is a React SPA that uses Typescript, babel, and webpack.
comunidades-unidas-internal exposes JSON REST APIs at https://database.cuutah.org/api.
Here are instructions to boot up this project locally so that you can change the code.
First, install the following:
- Git
- Docker. This will also install docker-compose.
- Node. Feel free to use nvm for this if you prefer, but any installation will work.
- Yarn. If you use Mac, this may require that you first install Homebrew.
Now, run the following commands in a terminal:
git clone [email protected]:JustUtahCoders/comunidades-unidas-internal.git
cd comunidades-unidas-internal
yarn install
yarn fix-everything
Now create a file inside of the comunidades-unidas-internal directory called .env
.
# Required for local dev - can be any value
KEYGRIP_SECRET=123
# Only needed if you're testing specific features
# Ask Joel or Leonel for the values to use if you need them
# USE_GOOGLE_AUTH=true
# GOOGLE_CLIENT_ID=<insert_id_here>
# GOOGLE_CLIENT_SECRET=<insert_client_secret_here>
# GOOGLE_CALLBACK_URL=http://localhost:8080/api/auth/google/callback
# GUEST_GITHUB_KEY=<insert_github_key_here>
# JPLS_USERNAME=<juntos_por_la_salud_ventanilla_username>
# JPLS_PASSWORD=<juntos_por_la_salud_ventanilla_password>
Now run the following command:
yarn develop
Now go to http://localhost:8080 in a browser.
This project is hosted by AWS Elastic Beanstalk. To deploy the code, simply merge a pull request to master, which will automatically trigger a deployment via Travis CI. You can see all current and previous deployments at https://travis-ci.org/JustUtahCoders/comunidades-unidas-internal.
If you need to make a change to the database schema, create a database migration by running the following command:
npx db-migrate create name-of-the-migration --sql-file
This will create a directory in the migrations
folder that has an "up" and a "down" sql file. The up file should create tables or modify columns,
the down file should drop tables and unmodify columns.
After creating a migration, you'll have to run npx db-migrate up
to run it against your local database. Alternatively, you can restart your local
environment (Ctrl + C and then yarn develop
). The migration will automatically run on the production database during the deployment in Travis CI.
From a terminal in the comunidades-unidas-internal directory, run the following commands:
docker-compose exec db bash
mysql -u root -ppassword # yep, it has two p's. The first is for password, the second is for the word password which is the password
# Now you'll be in the mysql shell
use local_db;
show tables;
SELECT * FROM clients;
# etc etc
Run the following commands in a terminal. Replace $HOSTNAME
, $USERNAME
, and $PASSWORD
with the correct values.
mysql -h $HOSTNAME -u $USERNAME -p$PASSWORD
# OR, if you don't have `mysql` installed on your computer
docker run -it --rm mysql mysql -h $HOSTNAME -u $USERNAME -p$PASSWORD
# Now you'll be in the mysql shell
use ebdb;
show tables;
SELECT * FROM clients;
Install ebcli. Then run eb ssh
. Our code is
inside of the /var/app/current/
directory.
If the production environment is having issues, you'll need access to Comunidades Unidas' AWS account to diagnose. Once you have access,
you'll need to install Python3 and
ebcli. Then run eb status
, eb logs
, and other commands
to try to diagnose.