Added docker compose, fixed all file paths, updated readme, fixed Async function bcrypt compare
This commit is contained in:
1 parent
51315bb8ed
commit
c8bcc59b52
10 files changed
+101
-36
No files matched your search
@@ -19,12 +19,15 @@ BlueWave uptime monitoring application
|
|||||||
1. [Installation (Client)](#client)
|
1. [Installation (Client)](#client)
|
||||||
2. [Configuration(Client)](#config-client)
|
2. [Configuration(Client)](#config-client)
|
||||||
- [Environment](#env-vars-client)
|
- [Environment](#env-vars-client)
|
||||||
3. [Installation (Server)](#server)
|
3. [Getting Started (Server)](#server)
|
||||||
4. [Configuration(Server)](#config-server)
|
- [Docker Compose Quickstart](#docker-quickstart)
|
||||||
- [Environment](#env-vars-server)
|
- [Manual Installation](#manual-install)
|
||||||
- [Database](#databases)
|
- [Install Server](#install-server)
|
||||||
- [Docker Images](#docker-images)
|
- [Environment](#env-vars-server)
|
||||||
5. [Endpoints](#endpoints)
|
- [Database](#databases)
|
||||||
|
- [(Optional) Dockerised Databases](#optional-docker-databases)
|
||||||
|
- [Start Server](#start-server)
|
||||||
|
4. [Endpoints](#endpoints)
|
||||||
###### Auth
|
###### Auth
|
||||||
- <code>POST</code> [/api/v1/auth/register](#post-register)
|
- <code>POST</code> [/api/v1/auth/register](#post-register)
|
||||||
- <code>POST</code> [/api/v1/auth/login](#post-login)
|
- <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>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/edit/{alertId}](#edit-alert)
|
||||||
- <code>POST</code> [/api/v1/alerts/delete/{alertId}](#delete-alert)
|
- <code>POST</code> [/api/v1/alerts/delete/{alertId}](#delete-alert)
|
||||||
6. [Error Handling](#error-handling)
|
5. [Error Handling](#error-handling)
|
||||||
7. [Contributors](#contributors)
|
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
|
1. Change directory to the `Server` directory
|
||||||
2. Install all dependencies by running `npm install`
|
2. Install all dependencies by running `npm install`
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
#### <u>Configuration</u> <a id="config-server"></a>
|
|
||||||
|
|
||||||
##### Environmental Variables <a id="env-vars-server"></a>
|
##### Environmental Variables <a id="env-vars-server"></a>
|
||||||
|
|
||||||
Configure the server with the following environmental variables:
|
Configure the server with the following environmental variables:
|
||||||
@@ -110,48 +139,51 @@ Configure the server with the following environmental variables:
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
##### Databases
|
##### Databases <a id="databases"></a>
|
||||||
|
|
||||||
This project requires a number of databases to run:
|
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.
|
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.
|
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>
|
<details>
|
||||||
<summary><b>MongoDB Image</b></summary>
|
<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> .`
|
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/mongo_data:/data/db --name uptime_database_mongo 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>
|
||||||
<details>
|
<details>
|
||||||
<summary><b>Redis Image</b></summary>
|
<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>`
|
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/redis_data:/data --name uptime_redis uptime_redis`
|
2. Run the image: `docker run -d -p 6379:6379 -v $(pwd)/redis/data:/data --name uptime_redis uptime_redis`
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<br/>
|
<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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
./docker
|
||||||
+2
-1
@@ -3,4 +3,5 @@ node_modules
|
|||||||
*.log
|
*.log
|
||||||
*.sh
|
*.sh
|
||||||
docker/mongo/data/*
|
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);
|
const user = await req.db.getUserByEmail(req, res);
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
|
|
||||||
const match = await user.comparePassword(req.body.password);
|
const match = await user.comparePassword(req.body.password);
|
||||||
if (match !== true) {
|
if (match !== true) {
|
||||||
throw new Error("Incorrect password");
|
throw new Error("Incorrect password");
|
||||||
|
|||||||
Executable
+20
@@ -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:
|
services:
|
||||||
server:
|
server:
|
||||||
image: uptime_server:latest
|
image: uptime_server:latest
|
||||||
@@ -10,6 +10,15 @@ services:
|
|||||||
- redis
|
- redis
|
||||||
- mongodb
|
- mongodb
|
||||||
redis:
|
redis:
|
||||||
image: uptime_redis
|
image: uptime_redis:latest
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
|
volumes:
|
||||||
|
- ./redis/data:/data
|
||||||
mongodb:
|
mongodb:
|
||||||
image: uptime_database_mongo
|
image: uptime_database_mongo:latest
|
||||||
|
command: ["mongod", "--quiet"]
|
||||||
|
ports:
|
||||||
|
- "27017:27017"
|
||||||
|
volumes:
|
||||||
|
- ./mongo/data:/data/db
|
||||||
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-alpine
|
FROM node:20
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -46,8 +46,9 @@ UserSchema.pre("save", async function (next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
UserSchema.methods.comparePassword = function (submittedPassword) {
|
UserSchema.methods.comparePassword = async function (submittedPassword) {
|
||||||
return bcrypt.compare(submittedPassword, this.password);
|
res = await bcrypt.compare(submittedPassword, this.password);
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = mongoose.model("User", UserSchema);
|
module.exports = mongoose.model("User", UserSchema);
|
||||||
Reference in new issue
Block a user