Node backend for handling student organization Digit website.
We have changed from Vagrant to Docker.
TODO: Update instructions
- Install Docker
Instructions from here and Google
-
Fork the project on GitHub
-
Clone the project
git clone <your fork url>/digit-backend
cd digit-backend- Optional: Moving from Vagrant to Docker
Delete the Vagrant image from VirtualBox.
Remove .vagrant folder on the project root
Remove ubuntu-bionic_*.cloudimg-console.log file
Remove both applied_*.json files from /migrations folder
- Start developing
docker-compose up
Docker creates two containers, database and the node app and everything is controlled by docker so no need to install npm on host.
Launch containers and start developing. Pm2 will take care of reloading application whenever files are changed. Recommended not to use too frequent auto save function on editor.
Docker commands
When container is running
Open database
docker exec -it digit_db psql -U digit -h localhost digit_dev
Show logs
docker container logs -f digit_db|digit_backend
Run bash commands from host terminal against running container:
docker exec digit_backend ps
Open a bash session into a running container:
docker container exec -it digit_backend /bin/sh
Start new container instance
Format is:
docker-compose [-f <compose.yaml>] run [--rm] <service name> <command>
Project has four services: backend and db for development and backendtest and dbtest for testing.
Open dev database connection:
docker-compose run --rm db psql -U digit -h db digit_dev
Open shell to dev container:
docker-compose run --rm backend /bin/sh
Testing can be performed by running tests in a additional test container:
docker-compose -f docker-compose-test.yaml run --rm backendtest npm test
Running cli options requires two dashes between npm script and
Jestcommand:npm test -- <command>See Jest's documents page
Test container creates own database and launches container on background.
Integration tests are located in /tests folder on project root which tests API-endpoints. All tests that requires API must run initializeApi before all and closeApi after all tests. These functions intialized server with help of supertest library and are located on testHelpers.js file.
If tests fail and error output is needed, comment out console.error(...) on ./app/index.js error handler (last function).
Write unit tests next to a testable component if possible.
Production server has a bare git repo which allows making pushes directly to it using SSH. Currently managed only by Niemisami.
- JWT authentication/registration
- Static Markdown/HTML page content
- Sponsors
- Navigation
- File upload
TODO
Fork the project -> do changes -> make a pull request.
git clone git@github.com:YOUR-USERNAME/digit-backend.git
cd into/cloned/fork-repo
git remote add upstream git://github.com/digitkoodit/digit-backend.git
git fetch upstream
git checkout -b blazing-feature
Create a new branch from the master branch so you can always pull latest changes from upstream origin without interrupting your own feature development if new changes are available.
git pull upstream master
or
git pull --rebase upstream master
Please follow the steps on the previous block. If . Rebasing helps to keep the project history more readable and therefore more maintainable. Here's a good article about what it means and why to use it: Git Fork Workflow Using Rebase.
Example of how to create a new feature/fix
# After the step 2. is performed
git checkout -b blazing-feature
# Make changes and commit with meaningful message
git commit -m "Add new blazing feature"
git checkout master
# Update local master and rebase moves possible changes after the ones which are already on production
git pull --rebase upstream master
git checkout blazing-feature
git rebase master
# Check that everything works and then perform merge or rebase
git checkout master
git merge blazing-feature
# Check that your new feature works on master branch and make a pull request
Take away:
- Only update
featurebranch to keep project more maintainable for everyone - Keep master always up to date with
upstream master - Keep commits small and on the topic
- Keep master always up to date with
upstream master!! - Rebase
featureto your master branch
The code in this project is licensed under MIT license.