A full stack web application built with ReactJS, NodeJS, ExpressJS, and MySQL.
There are 2 options for connecting to the database:
-
You can set up your own MySQL database using the SQL scripts provided in the "database" folder. Run the
CreateTableQueries.sql
script first, then run thesampleInsertQuery.sql
script. -
We have also hosted a database on AWS RDS. If you want to use this database, see the section below about setting up your
.env
file for the API.
Connecting to the API (The Endpoint for database and backend has been taken down! Please use the local option!)
Similar to the database, you have 2 options here: you can set up your own .env
file and start an instance of the API locally, or you can use the instance of the API that we have hosted on AWS Elastic Beanstalk. The API hosted on AWS is also automatically connected to the database hosted on AWS.
-
The simplest way to use the API is to use the instance hosted on AWS. Simply direct all API requests to the base address
backend-env-1.eba-gjinncph.us-west-1.elasticbeanstalk.com
, followed by the endpoint. For example, to connect to the/api/login
endpoint, you would send a request tobackend-env-1.eba-gjinncph.us-west-1.elasticbeanstalk.com/api/login
. -
If you want to start an instance of the API locally, you will need to create your own
.env
file in the root of thebackend-api
folder. This file needs to contain 5 variables:DB_HOST
: The host url of the database. If you have used your own MySQL instance, this will be"localhost"
. If you want to use the MySQL instance that is hosted on AWS, set this to"database-1.c8hq2lzw6okk.us-west-1.rds.amazonaws.com"
.DB_USER
: The MySQL user's username. Most likely"root"
.DB_PASS
: The MySQL user's password.DB_NAME
: The name of the database to connect to. This will almost always be"library"
.JWT_SECRET
: The secret to use for JWT authentication. Can be any string you want.- Here is an example
.env
file, set up to use the AWS database and a JWT secret of "supersecretsecret":DB_HOST="database-1.c8hq2lzw6okk.us-west-1.rds.amazonaws.com" DB_USER="root" DB_PASS="password" DB_NAME="library" JWT_SECRET="supersecretsecret"
After setting up your
.env
file, to start the API you just need to navigate to thebackend-api
folder and runnpm start
. If you have not yet runnpm install
, you will need to do that first. Once the server is started, you will direct all API requests tohttp://localhost:3001
, followed by the endpoint. For example, to connect to the/api/login
endpoint, you would send a request tohttp://localhost:3001/api/login
.
Our application uses JWT tokens for authentication, which need to be provided in the "Authorization" header alongside every request (except for login and create student, see API documentation for more details). The format of the header content will be "Bearer <token>"
. To get a token, send a request to /api/login
with login details, and an access token will be returned in the response, along with the permission level of the user.
There are some default users included in the database for testing purposes. The login details are:
- Admin user:
admin:password
- Librarian user:
librarian:password
- Student user:
student:password
Refer to the API documentation for more details about the required permission level of different requests.
The full API documentation generated by Postman, which includes example requests and responses and details about required permissions for requests, can be found here: API Documentation.
You will need to set up a .env
file in the root of the cpsc471-libmansys-frontend
folder. This file contains 1 variable:
REACT_APP_BE_ENDPOINT
: The base address of the API. To use the API hosted on AWS, set this to"backend-env-1.eba-gjinncph.us-west-1.elasticbeanstalk.com/api/login"
. If you started the API locally, set this to"http://localhost:3001"
instead.
Once the .env
file is set up, simply run npm start
(and npm install
first if you haven't), and then navigate to http://localhost:3000
to view the front-end.