An uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about their availability, average response time, and total uptime/downtime.
- Before you can run this app, you need to have the following installed on your system:
- Node.js
- Docker
- Getting started
- Clone this repository to your local machine:
git clone https://github.com/MinaMamdouh2/uptime-monitoring-server.git
- Navigate to the project directory:
cd uptime-monitoring-server
- Install the app's dependencies:
npm install
- Create a .env file in the project root as .env.example
- Clone this repository to your local machine:
- Running the app with npm start
- To run the app using npm start, use the following command:
npm start
- This will start the app on the port specified in your .env file.
- To run the app using npm start, use the following command:
- Running the app with Docker
- Set
NODE_ENV
in the .env file toproduction
- Build the Docker image:
docker-compose build
- Start the container:
docker-compose up
- This will start the app inside a Docker container on the port specified in your .env file.
- Stopping the app:
docker-compose down
- Set
- Running tests
- Before running the tests, make sure that the app is running with
npm start
. - To run the tests, use the following command:
npm run tests
- Note:- After running the tests the database will be cleared.
- Before running the tests, make sure that the app is running with
- User Creation Process
- A user sends a post request to the server with an email and password; an email with a JWT token is sent to him, and he uses this token to verify his email.
- APIs used:
- POST: http://localhost:3000/users -->body: {"email": "[email protected]", "password": "@Test1234"}
- POST: http://localhost:3000/auth/verify-email --> body: {"jwtToken": "eyJhbGciOiJIUR5cCI6IkpXVCJ9.asfasfasfas.iqowrqorq"}
- APIs used:
- You can resend the verification email through this API.
- API used:
- POST: {{URL}}/auth/send-verification-email --> body: {"email:"[email protected]"}
- API used:
- Role Authorization flow:
- Each user can be assigned a role "user" or "admin", by default all users created are assigned to "user" role.
- Users can only create URL checks & generate reports
- APIs used:
- POST: http://localhost:3000/users --> body: {"email": "[email protected]", "password": "@Test1234",
"role": "admin"
}
- POST: http://localhost:3000/users --> body: {"email": "[email protected]", "password": "@Test1234",
- APIs used:
- Admins can only get users & delete users
- APIs used:
PROTECTED
GET: {{URL}}/usersPROTECTED
GET: {{URL}}/users/:idPROTECTED
DELETE: {{URL}}/users/:id
- APIs used:
- Each user must login to use any URL checks CRUDs or Reports CRUDs
- API used: {{URL}}/auth/login --> body: {"email": "[email protected]", "password": "@Test1234"}
- This API returns jwtToken which must be set in
Authorization Bearer
TokenProtected APIs
.
- This API returns jwtToken which must be set in
- API used: {{URL}}/auth/login --> body: {"email": "[email protected]", "password": "@Test1234"}
- A user sends a post request to the server with an email and password; an email with a JWT token is sent to him, and he uses this token to verify his email.
- URL Check Creation Proccess
- A user creates a URL check, which is then sent to the monitor URL function, which pings the server on an interval basis.
- The check status is only considered
available
if only the server responds with status code2XX
otherwise it is considereddown
- If URL check consists of
assert.statusCode
, if the serverresponse's status != assert.statusCode
; it is considereddown
- An email with a
down
notification is sent to the user's email upon exceeding the checkthreshold
- An email with an
available
notification is sent to the user's email upon exceeding the checkthreshold
& comes backavailable
- The URL check is terminated if the check or the user who created it has been
deleted
- APIs used:
-
PROTECTED
POST: {{URL}}/checks --> body: {"name": "check1", "url":"localhost", "protocol": "HTTP", "port": 5000, "path": "/api", "threshold": 3, "ignoreSSL": false,"assert":{ "statusCode": 200}, "webhook": "http://localhost:5000/webhook", "httpHeaders":{ "post":{"header1": 1}}}PROTECTED
POST: {{URL}}/checks --> To check forbasic authentication
--> body:{"name": "check2","url":"httpbin.org/basic-auth/foo/bar","protocol": "http", "tags": ["localhost", "my enviroment"], "authentication":{ "username": "foo","password": "bar"},"ignoreSSL": false}PROTECTED
POST: {{URL}}/checks --> To checkignore broken/expired SSL certificates
--> body:{ "name": "check71", "url":"expired.badssl.com", "protocol": "HTTPS", "tags": ["trial3"], "threshold": 3, "ignoreSSL": true, "webhook": "http://localhost:5000/webhook", "httpHeaders":{ "post":{ "header1": 1}}}PROTECTED
GET: {{URL}}/checks/:idPROTECTED
GET: {{URL}}/checks?page=1&limit=10&tags=localhost&tags=dev&tags=productionPROTECTED
PUT: {{URL}}/checks/:idPROTECTED
DELETE: {{URL}}/checks/:id
- APIs used:
-
- The check status is only considered
- A user creates a URL check, which is then sent to the monitor URL function, which pings the server on an interval basis.
- A user can obtain a detailed report for a single URL check or a group of URL checks.
- APIs used:
PROTECTED
GET: {{URL}}/reports/:id?page=1&limit=10PROTECTED
GET: {{URL}}/reports/?page=1&limit=10&tags=env&tags=dev
- APIs used: