mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-15 06:09:44 -06:00
Added docker compose, fixed all file paths, updated readme, fixed Async function bcrypt compare
This commit is contained in:
90
README.md
90
README.md
@@ -19,12 +19,15 @@ BlueWave uptime monitoring application
|
||||
1. [Installation (Client)](#client)
|
||||
2. [Configuration(Client)](#config-client)
|
||||
- [Environment](#env-vars-client)
|
||||
3. [Installation (Server)](#server)
|
||||
4. [Configuration(Server)](#config-server)
|
||||
- [Environment](#env-vars-server)
|
||||
- [Database](#databases)
|
||||
- [Docker Images](#docker-images)
|
||||
5. [Endpoints](#endpoints)
|
||||
3. [Getting Started (Server)](#server)
|
||||
- [Docker Compose Quickstart](#docker-quickstart)
|
||||
- [Manual Installation](#manual-install)
|
||||
- [Install Server](#install-server)
|
||||
- [Environment](#env-vars-server)
|
||||
- [Database](#databases)
|
||||
- [(Optional) Dockerised Databases](#optional-docker-databases)
|
||||
- [Start Server](#start-server)
|
||||
4. [Endpoints](#endpoints)
|
||||
###### Auth
|
||||
- <code>POST</code> [/api/v1/auth/register](#post-register)
|
||||
- <code>POST</code> [/api/v1/auth/login](#post-login)
|
||||
@@ -50,8 +53,8 @@ BlueWave uptime monitoring application
|
||||
- <code>GET</code> [/api/v1/alerts/{alertId}](#get-alert-alert-id)
|
||||
- <code>POST</code> [/api/v1/alerts/edit/{alertId}](#edit-alert)
|
||||
- <code>POST</code> [/api/v1/alerts/delete/{alertId}](#delete-alert)
|
||||
6. [Error Handling](#error-handling)
|
||||
7. [Contributors](#contributors)
|
||||
5. [Error Handling](#error-handling)
|
||||
6. [Contributors](#contributors)
|
||||
|
||||
---
|
||||
|
||||
@@ -80,17 +83,43 @@ BlueWave uptime monitoring application
|
||||
|
||||
---
|
||||
|
||||
### Server
|
||||
### Getting Started (Server)
|
||||
|
||||
#### <u>Installation</u>
|
||||
#### <u>Docker Quickstart</u> <a id="docker-quickstart"></a>
|
||||
|
||||
The fastest way to start the server is to use our Dockerfiles and [Docker Compose](https://docs.docker.com/compose/).
|
||||
|
||||
To get the server up and running you need to:
|
||||
|
||||
1. In the `Server/docker` directory run the build script `build_images.sh` to build docker images for the server, Redis database, and MongoDB database.
|
||||
2. In the `Server/docker` directory, create a `.env` file with the [requried environtmental variables](#env-vars-server). Sample file:
|
||||
|
||||
```
|
||||
CLIENT_HOST="http://localhost:5173"
|
||||
JWT_SECRET="my_secret"
|
||||
DB_TYPE="MongoDB"
|
||||
DB_CONNECTION_STRING="mongodb://mongodb:27017/uptime_db"
|
||||
REDIS_HOST="redis"
|
||||
REDIS_PORT=6379
|
||||
SYSTEM_EMAIL_ADDRESS="<email>"
|
||||
SENDGRID_API_KEY="<api_key>"
|
||||
LOGIN_PAGE_URL="<login_page"
|
||||
```
|
||||
|
||||
3. In the `Server/docker` directory run `docker compose up` to run the `docker-compose.yaml` file and start all three images.
|
||||
|
||||
That's it, the server is ready to use.
|
||||
<br/>
|
||||
|
||||
#### <u>Manual Install</u> <a id="manual-install"></a>
|
||||
|
||||
##### Install Server <a id="install-server"></a>
|
||||
|
||||
1. Change directory to the `Server` directory
|
||||
2. Install all dependencies by running `npm install`
|
||||
|
||||
<br/>
|
||||
|
||||
#### <u>Configuration</u> <a id="config-server"></a>
|
||||
|
||||
##### Environmental Variables <a id="env-vars-server"></a>
|
||||
|
||||
Configure the server with the following environmental variables:
|
||||
@@ -110,48 +139,51 @@ Configure the server with the following environmental variables:
|
||||
|
||||
<br/>
|
||||
|
||||
##### Databases
|
||||
##### Databases <a id="databases"></a>
|
||||
|
||||
This project requires a number of databases to run:
|
||||
|
||||
1. Main database for the application. This project includes an implementation for a MongoDB database as well as a MongoDB Docker image.
|
||||
2. A Redis database is required for the Queue implementation in the PingService. This project includes a Redis docker image.
|
||||
|
||||
You may run your own databases locally, or you may use the docker images included in the project to get up and running quickly.
|
||||
You may use the included Dockerfiles to spin up databases quickly if you wish.
|
||||
|
||||
###### (Optional) Running Docker Images <a id="docker-images"></a>
|
||||
###### (Optional) Dockerised Databases <a id="optional-docker-databases"></a>
|
||||
|
||||
Docker images are located in `./Server/docker`
|
||||
Dockerfiles for the server and databases are located in the `./Server/docker` directory
|
||||
|
||||
<details>
|
||||
<summary><b>MongoDB Image</b></summary>
|
||||
Located in `./Server/docker/mongo`
|
||||
Location: `./Server/docker/mongoDB.Dockerfile`
|
||||
|
||||
The `./Server/docker/mongo/mongo_data` folder should be mounted to the MongoDB container in order to persist data.
|
||||
The `./Server/docker/mongo/data` directory should be mounted to the MongoDB container in order to persist data.
|
||||
|
||||
From the `mongo` folder run
|
||||
From the `Server/docker` directory run
|
||||
|
||||
1. Build the image: `docker build -t <db_image_name> .`
|
||||
2. Run the docker image: `docker run -d -p 27017:27017 -v $(pwd)/../mongo/mongo_data:/data/db --name uptime_database_mongo uptime_database_mongo`
|
||||
1. Build the image: `docker build -f mongoDB.Dockerfile -t uptime_database_mongo .`
|
||||
2. Run the docker image: `docker run -d -p 27017:27017 -v $(pwd)/mongo/data:/data/db --name uptime_database_mongo uptime_database_mongo`
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary><b>Redis Image</b></summary>
|
||||
Located in `./Server/docker/redis`
|
||||
Location `./Server/docker/redislDockerfile`
|
||||
|
||||
the `./Server/docker/redis/redis_data` folder should be mounted to the Redis container in order to persist data.
|
||||
the `./Server/docker/redis/data` directory should be mounted to the Redis container in order to persist data.
|
||||
|
||||
From the `Redis` folder run
|
||||
From the `Server/docker` directory run
|
||||
|
||||
1. Build the image: `docker build -t <db_image_name>`
|
||||
2. Run the image: `docker run -d -p 6379:6379 -v $(pwd)/../redis/redis_data:/data --name uptime_redis uptime_redis`
|
||||
1. Build the image: `docker build -f redis.Dockerfile -t uptime_redis .`
|
||||
2. Run the image: `docker run -d -p 6379:6379 -v $(pwd)/redis/data:/data --name uptime_redis uptime_redis`
|
||||
</details>
|
||||
|
||||
<br/>
|
||||
|
||||
#### <u>Starting the Development Server</u>
|
||||
##### Starting the Development Server <a id="start-server"></a>
|
||||
|
||||
1. run `npm run dev` to start the development server
|
||||
- run `npm run dev` to start the development server
|
||||
|
||||
OR
|
||||
|
||||
- run `node index.js` to start server
|
||||
|
||||
---
|
||||
|
||||
|
||||
1
Server/.dockerignore
Normal file
1
Server/.dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
./docker
|
||||
3
Server/.gitignore
vendored
3
Server/.gitignore
vendored
@@ -3,4 +3,5 @@ node_modules
|
||||
*.log
|
||||
*.sh
|
||||
docker/mongo/data/*
|
||||
docker/redis/data/*
|
||||
docker/redis/data/*
|
||||
!docker/build_images.sh
|
||||
@@ -88,6 +88,7 @@ const loginController = async (req, res, next) => {
|
||||
const user = await req.db.getUserByEmail(req, res);
|
||||
|
||||
// Compare password
|
||||
|
||||
const match = await user.comparePassword(req.body.password);
|
||||
if (match !== true) {
|
||||
throw new Error("Incorrect password");
|
||||
|
||||
20
Server/docker/build_images.sh
Executable file
20
Server/docker/build_images.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# Change directory to root Server directory for correct Docker Context
|
||||
cd ..
|
||||
|
||||
# MongoDB
|
||||
mongoDB="./docker/mongoDB.Dockerfile"
|
||||
|
||||
# Redis
|
||||
redis="./docker/redis.Dockerfile"
|
||||
|
||||
# Server
|
||||
server="./docker/server.Dockerfile"
|
||||
|
||||
docker build -f $mongoDB -t uptime_database_mongo .
|
||||
docker build -f $redis -t uptime_redis .
|
||||
docker build -f $server -t uptime_server .
|
||||
|
||||
echo "All images built"
|
||||
@@ -1,4 +1,4 @@
|
||||
version: '3'
|
||||
version: "3"
|
||||
services:
|
||||
server:
|
||||
image: uptime_server:latest
|
||||
@@ -10,6 +10,15 @@ services:
|
||||
- redis
|
||||
- mongodb
|
||||
redis:
|
||||
image: uptime_redis
|
||||
image: uptime_redis:latest
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- ./redis/data:/data
|
||||
mongodb:
|
||||
image: uptime_database_mongo
|
||||
image: uptime_database_mongo:latest
|
||||
command: ["mongod", "--quiet"]
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- ./mongo/data:/data/db
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM node:20-alpine
|
||||
FROM node:20
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -46,8 +46,9 @@ UserSchema.pre("save", async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
UserSchema.methods.comparePassword = function (submittedPassword) {
|
||||
return bcrypt.compare(submittedPassword, this.password);
|
||||
UserSchema.methods.comparePassword = async function (submittedPassword) {
|
||||
res = await bcrypt.compare(submittedPassword, this.password);
|
||||
return res;
|
||||
};
|
||||
|
||||
module.exports = mongoose.model("User", UserSchema);
|
||||
|
||||
Reference in New Issue
Block a user