The County Committee Sunlight Project App
App for ccsunlight.org
- feat: parser for district part mappings
- feat: User can see what part their ED is.
- fix: cc member cannont save. sex:
nullis not a valid enum value for path
- data: Add part to cc lists
- bug: Part mapping can be applied if already approved
- fix: importer not returning CSV validation result message in admin
- refactor: to postgres
This project uses Feathers. An open source web framework for building modern real-time applications.
The admin uses "admin on rest".
The data is stored in a local dockerized mongo and the entire image is backed up periodically.
The app runs via docker but you'll have to install those two applications manually before starting.
- Mongo DB 3.6
- Node 10.16 with NPM
Docker creates containers with the specs below. You can try to use without docker, but if you can use docker, it will install and set everything up automatically for you.
*On production server there is a NGINX reverse proxy to enable SSL. It's not necessary for local dev.
The app will automatically install these itself if you have docker installed.
- Material Design Lite
- Admin On Rest
- NGINX - for reverse proxy for SSL on production
- PDF-To-Text Extract
- Google Maps API
Getting up and running is as easy as 1, 2, 3...10
git clone [repo link] /your/app/path
You'll need to make a data directory if you don't already have one on your host machine
sudo mkdir -p /data/db
The first time we need to create the volume for the DB
docker volume create --name=cc-db
The first time you need to comment out this line in docker-compose.yml for local dev (Do NOT do this on any public facing apps!)
# command: mongod --auth
Spin up and ssh into docker container to run install scripts:
SSH into container
This will create three docker containers, one with mongo, the other with node and a persistent storage docker container.
You should see a prompt that looks like this:
npm run install
This will install the node dependancies and runs migrations. It's important the this is done inside the running app container otherwise there may be errors with bcrypt. (see troubleshooting below)
You will be prompted to record the superadmin login and pw. You will not be given another opportunity to see this so make sure you write it down.
Start your app
Alternatively you could run through PM2 with
./node_modules/.bin/pm2 start, which is a process manager. For dev you may not want this.
When the app starts for the first time it will run additional imports for the map geometry which will take a little while.
Go to your homepage http://localhost
Try logging into the admin with the sadmin creds you saved before. http://localhost/cc-admin/
Report any bugs in the issues section of the repo.
If you have proprietary DB setup info update the ".env" file to your settings. Otherwise the DB vars can be left as is for dev, however, it is strongly discouraged to leave for production use as this DB would have no PW!
For email sending (reset pw account activation) you'll need a GMAIL account, and is suggested you get a new one for this project.
Enter a alphanumeric key for AUTHENTICATION_SECRET. (512 chars recommended for production).
Deploying can be done by running the "deploy-prod.sh" script in the scripts folder.
- Merge and push changes to the master branch.
- From your local terminal in the root run:
- It will prompt you for a password. Enter password and hit enter.
- The script will ssh into the droplet, pull down the latest changes from master and destroy and recreate and spinup the docker nodes.
note: There will be approximately 1 to 3 minutes of downtime while this happens.
Feathers uses a restful, enveloped JSON API. The API docs and can be found at:
More info on how to use can be found here: https://docs.feathersjs.com/api/client/rest.html
bcrypt npm error
If you npm install outside of the docker, the bcrypt inside of the docker will error, and vice versa, which kills the npm install process.
To fix delete the node_modules folder and do npm install inside the docker in that case. Otherwise, comment out bcrypt in package.json. It's used for the email invite to the admin so is only necessary for that section.
App not responding
Most of the time this is due to memory usage. The Mongo instance uses a good amount of memory. I resized the instance to a bigger droplet and it hasn't crashed since then. If it does get a memory overload, run the "restart-prod.sh" script in the scripts folder.
This will restart the app on the actual server. If the issue still occurs, this could mean the droplet itself needs to be restarted. If so follow the digital ocean instructions to power off and restart the droplet. Then run the "restart-prod.sh" in the scripts folder.
Everything is broken
The entire droplet is backed up weekly. You should be able to restore a backup. I haven't actually done this yet, so you may have to run the spinup script. Just keep in mind if the issue is with the latest code and you pull the changes, it will overwrite the code in the backup. Also this will delete any changes made on that instance since the last backup. https://cloud.digitalocean.com/droplets/45901904/backups?i=af9b24
The SSL cert was generated following this tutorial https://code.lengstorf.com/deploy-nodejs-ssl-digitalocean/
Managing Committee Data
This is still a WIP. There are some things that are automated and some that need manual scripting. It is the aim of this project to automate the flow of data.
Importing Certified List
From the command line you need to run the following:
If successful, this will import into the "imports" section in the admin. You will be able to approve the list and then it will become.
Importing Party Call
The party call determines what EDs and positions in those EDs are open for an upcoming election.
node scripts/import-party-call -f "path/to/your/party-call.csv" -c "Kings" -p "Democratic" -e "September 13, 2018" -s "NY"
The CSV format is as follows:
district_key,County Committee 77001,2 77002,2 77003,2
Creating County Committee
npm test and all your tests in the
test/ directory will be run.
Feathers has a powerful command line interface. Here are a few things it can do:
$ npm install -g feathers-cli # Install Feathers CLI $ feathers generate service # Generate a new Service $ feathers generate hook # Generate a new Hook $ feathers generate model # Generate a new Model $ feathers help # Show all commands
For more information on all the things you can do with Feathers visit docs.feathersjs.com.
- Updating readme with dev instructions
- Creating new branches
- Initial release
Copyright (c) 2016
Licensed under the MIT license.