Skip to content

A REST API backend system for the UniPal app, made with NodeJS

License

Notifications You must be signed in to change notification settings

cyntaria/UniPal-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

UniPal REST API Using Express With MVC Architecture

Node Build, Test And Lint CI Build And Deploy To Azure Pull Request Labeler Deploy To Heroku GitHub issues GitHub stars Lines of code GitHub license

BadgeNodeJS BadgeExpress BadgeMySQL BadgeAzure BadgeAzureAppService BadgeHeroku

πŸ“ Documentation

The documentation was generated using Postman and is divided into collections at the following URLs:

Endpoint URL
Auth https://documenter.getpostman.com/view/13348269/TzzHnZDS
Hobbies https://documenter.getpostman.com/view/13348269/U16dT95z
Interests https://documenter.getpostman.com/view/13348269/U16evoaD
Campuses https://documenter.getpostman.com/view/13348269/U16gNmMg
Programs https://documenter.getpostman.com/view/13348269/U16gNmRy
Student Statuses https://documenter.getpostman.com/view/13348269/U16gNmWU
Students https://documenter.getpostman.com/view/13348269/U16jLkDx
Activity Statuses https://documenter.getpostman.com/view/13348269/U16kpjou
Activity Types https://documenter.getpostman.com/view/13348269/U16kq4gc
Campus Spots https://documenter.getpostman.com/view/13348269/U16nJNvi
Activities https://documenter.getpostman.com/view/13348269/UUxtEW2F
Student Connections https://documenter.getpostman.com/view/13348269/UUy7bjZY
Hangout Requests https://documenter.getpostman.com/view/13348269/UV5WCHBi
Reaction Types https://documenter.getpostman.com/view/13348269/UV5WCdMP
Posts https://documenter.getpostman.com/view/13348269/UV5ZAw6H
Subjects https://documenter.getpostman.com/view/13348269/UV5cAbDZ
Timeslots https://documenter.getpostman.com/view/13348269/UV5cAvrF
Classrooms https://documenter.getpostman.com/view/13348269/UVBzmUFC
Teachers https://documenter.getpostman.com/view/13348269/UVC2HUx5
Teacher Reviews https://documenter.getpostman.com/view/13348269/UVJZmxLn
Terms https://documenter.getpostman.com/view/13348269/UVJigZ54
Classes https://documenter.getpostman.com/view/13348269/UVR5q8Xn
Timetables https://documenter.getpostman.com/view/13348269/UVXgKwEp

πŸ“€ Installation

1. Getting Started

# Clone this repo to your local machine using
git clone https://github.com/cyntaria/UniPal-Backend

# Get into the directory
cd UniPal-Backend

# Make it your own
rm -rf .git && git init (For Linux/MacOS)
rm .git -r -fo; git init (For Windows PowerShell)

# Copy example.env and create your own .env file in envs folder
cp .env.example envs/.env

# Move into the envs dir
cd envs

# Edit .env file and add your mysql username, password and db name, host,
# port, jwt_secret
vscode .env

# Create different .env.{NODE_ENV} file for each environment and override only your
# required variables. The missing ones will be loaded from .env by default.
# For example if you want dev, production and test environments:
cp .env .env.dev
cp .env.dev .env.production
cp .evn.dev .env.test

# When the NODE_ENV variable is set while running, the correct .env loads automatically.
# e.g. Setting NODE_ENV=production is going to load the .env.production file

# Add a gitignore to ignore node_modules and your .env file
echo -e 'node_modules \n envs \n' >> .gitignore

2. Setting up node js

# Install dependencies
npm install

# Run the server locally with default .env file
npm start

# Run the server in dev mode with nodemon with .env.dev file
npm run dev

# While deploying to production with .env.production file
npm run production

:electron: Setup CI (Github Actions)

If you want to run the github testing and PR labelling workflows in the CI then:

Create the following repository secrets:

  • DB_HOST: your_db_host (If using CI mysql service set to 127.0.0.1)
  • DB_USER: your_db_user (If using CI mysql service set this to 'root')
  • DB_PASS: your_db_password (If using CI mysql service set this to 'root')
  • DB_TEST_DATABASE: your_test_database_name
  • SENDGRID_API_KEY: value should be your .env file variable => sendgrid_api_key
  • SENDGRID_SENDER: value should be your .env file variable => from_email
  • SECRET_JWT: value should be your .env file variable => your_secret
  • PRODUCTION_ENV: contents of the base .env + .env.production files
  • HEROKU_API_KEY: value for the heroku api key
  • AZURE_PUBLISH_PROFILE: the contents of the downloaded publish profile from Azure
  • WEBAPP_NAME: name of the deployed webapp, should match heroku/azure project name

πŸ“• Important Notes

  • The healthcheck endpoint is to ensure the status of the API from the CI so we can be sure we are deploying a working API only.
  • If you add/remove/change the names of any folders/file extensions make sure to update the labeler.yml

Enjoy :)

πŸ” Security

Take the following steps to ensure security of configurations

# 1. Convert the envs folder to zip file
# 2. Encrypt it using gpg passphrase
gpg --output encrypted_envs.gpg --symmetric envs.rar
# 3. Decrypt it using gpg passphrase
gpg --output envs.rar --decrypt encrypted_envs.gpg

πŸ”§ Tech

This example uses a number of open source projects to work properly:

πŸ“‘ License

UniPal-Backend Β© 2021 by Abdur Rafay Saleem is licensed under CC BY 4.0