This backend app handles requests from a React Native mobile app and a React admin dashboard web app.
Table of Contents
- Digital Ocean
- App Platform
- PostgreSQL database
- Spaces
- Node.js / Express.js
- Prisma ORM
- git
- npm
- Node.js
- A local PostgreSQL database
-
Clone the repo
git clone https://github.com/unifygiving/UG-Backend-Stage.git
-
Install NPM packages
npm install
-
Create a database called
dev_dbin your local PostgreSQL. -
Run
npx prisma generatefor recreating connection. -
Run
npm run prisma db pushto push on db -
Create a .env file at the root of the project, and add the following variables to it:
NODE_ENV="development" JWT_SECRET="make_up_a_secret_for_development" DATABASE_URL="your_local_db_connection_string_here" API_BASE_URL="http://localhost:3000" ZOHO_EMAIL_FROM_NAME="Sharon at Unify Giving" ZOHO_EMAIL_ADDRESS="contact@unifygiving.com" ZOHO_APP_PASSWORD="ask_project_owner_for_this_password"
-
Contact the owner of the project for additional environment variables, if needed.
-
This app uses Prisma ORM. Check the Prisma docs for how to use it https://www.prisma.io/.
- Hostname/address: dpg-cu9sq23qf0us73c4n5gg-a.frankfurt-postgres.render.com
- Port: 5432
- Maintenance Database: unify_test_db_c9eq
- Username: unify_test_db_c9eq_user
- Password: sPne2ZkrcECVFbSfLbHD8GNpdTgDDLTy
To connect to the staging database the DATABASE_URL variable within the env should look like this.
#Staging Database
DATABASE_URL="postgresql://unify_test_db_c9eq_user:sPne2ZkrcECVFbSfLbHD8GNpdTgDDLTy@dpg-cu9sq23qf0us73c4n5gg-a.frankfurt-postgres.render.com/Staging"To connect to the development database the DATABASE_URL variable within the env should look like this.
#Development Database
DATABASE_URL="postgresql://unify_test_db_c9eq_user:sPne2ZkrcECVFbSfLbHD8GNpdTgDDLTy@dpg-cu9sq23qf0us73c4n5gg-a.frankfurt-postgres.render.com/Development"#API URL
API_BASE_URL="https://ug-backend-58bx.onrender.com"Contact @DanWSDev (Slack - Daniel Stannard) if any issues with connecting
- Start the project (the dev script uses
nodemonto auto restart the server on file save)npm run dev
- Visit the url to check that it works: http://localhost:3000
- Visit the API docs by adding
/api-docsto the url like so: http://localhost:3000/api-docs
- Start by going to GitHub:
- Go to the
Issuestab, and select the issue you want to work on. - Add a comment to the issue (something simple like, "I'll work on this.")
- Assign yourself to that issue.
- Go back to the main code page and open the branch dropdown menu.
- In the dropdown enter the name of a new branch for you to work on (prefix the issue number to the name, like
12-get-address-endpoint), and then click onCreate branch:...in the dropdown.
- Go to the
- Now go back to your machine:
git checkout mainTo switch to the main branch.git pullTo pull in the latest code from the GitHub repo.git checkout <name of the branch you created>git statusTo check that you are on your branch and not main.- Write code and make changes for the issue you are working on. When you are all done making changes, make sure you are still on your branch, then continue to the next steps.
git stashTo stash your local changes. (This strategy reduces merge conflicts)git pull origin mainThis fetches commits from the main branch of the origin remote (into the local origin/main branch), and then it merges origin/main into the branch you currently have checked out.git stash applyTo merge your local changes (you will likely see a notice that you need to add and commit)git add .To add all changed files to the staging areagit commit -m "Issue #12. Your message here."To commit the changesgit pushTo push the changes to the GitHub repo
- Go back to GitHub:
- There should be a notice towards the top. Click on
Compare and pull request. - Type a comment and click
Create pull request. - In the right side menu, select a reviewer by clicking
Requestnext to a suggested reviewer, or click onReviewersto select someone. - Wait for the reviewer to review your code. If everything looks fine, the reviewer will merge the pull request on GitHub, and delete your branch on GitHub. Then on your machine, you can switch back to your main branch, and delete the branch you were working on, since it has been accepted and merged.
- If the reviewer wants you to make changes to your pull request, watch this short video for an example of how to do code reviews on GitHub https://www.youtube.com/watch?v=UpBpb0j7IKA.
- There should be a notice towards the top. Click on
- This app was initially scaffolded out with
express-generator, with the--no-viewoption. See Express application generator for more details. - The
binfolder contains scripts. In this folder is a file namedwww(no file extension). Thewwwfile is the script that starts the app as a web server. Thebinfolder can also contain scripts for testing or other stuff. - The
docsfolder contains documents that describe this backend service. - The
middlewarefolder contains files with middleware functions. - The
prismafolder contains the prisma schema and the database migration files. - The
publicfolder contains static files to be served by the express server. - The
routesfolder contains the route files for defining the API endpoints. The API is further separated into versions. In the future, if there are significant changes that need to be made, then create av2folder for the new version. - The
utilsfolder contains files with utility functions. - The
app.jsfile is where the route files are imported and registered for use by the app, along with other services and middleware. - The
db_create.sqlfile contains the SQL statements to create the database tables, functions, triggers, etc.. - The
db_share.jsfile is where the prisma client is instantiated and exported. This way we only create one prisma client and share it with the rest of the app. - The
swagger-generate.jsfile contains the code that generates theswagger-ouput.jsonfile. The swagger generator is run every time you start the server withnpm run dev, and it overwrites the swagger output file. The swagger output file is used by swagger to create the web page for the API docs. Once the server is running, you can view the docs at http://localhost:3000/api-docs .