9.9 KiB
icon
| icon |
|---|
| sign-posts-wrench |
Installing Uptime Manager
Quickstart for users (quick method)
- Download our Docker compose file
- Run
docker compose upto start the application - Now the application is running at
http://localhost
Optional Config:
- If you want to monitor Docker containers, uncomment this line in
docker-compose.yaml:
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock:ro
This gives the app access to your docker daemon via unix socket, please be aware of what you are doing.
Quickstart for users (remote server)
- Download our Docker compose file
- Edit the
UPTIME_APP_API_BASE_URLvariable in the docker-compose file to point to your remote server. - Run
docker compose upto start the application - Now the application is running at
http://<remote_server_ip>
Optional Config:
- If you want to monitor Docker containers, uncomment this line in
docker-compose.yaml:
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock:ro
This gives the app access to your docker daemon via unix socket, please be aware of what you are doing.
Quickstart for developers
{% hint style="info" %} Make sure you change the directory to the specified directories, as paths in commands are relative. {% endhint %}
Cloning and initial setup
- Clone this repository.
- Checkout the
developbranchgit checkout develop
Setting up Docker images
- Change directory to the
Docker/devdirectory - Build the docker images by running the
build_images.shscript - Run
docker run -d -p 6379:6379 -v $(pwd)/redis/data:/data --name uptime_redis uptime_redis - Run
docker run -d -p 27017:27017 -v $(pwd)/mongo/data:/data/db --name uptime_database_mongo uptime_database_mongo
Server setup
- CD to
Serverdirectory, and runnpm install - While in
Serverdirectory, create a.envfile with the required environmental variables - While in the
Serverdirectory, runnpm run dev
Client setup
- CD to
Clientdirectoryrun npm install - While in the
Clientdirectory, create a.envfile with the required environmental variables - While in the
Clientdirectory runnpm run dev
Access the application
- Client is now running at
localhost:5173 - Server is now running at
localhost:5000
Manual installation
Client installation
- Change directory to the
Clientdirectory - Install all dependencies by running
npm install - Add a
.envfile to theClientdirectory with the following options:
Environment variables
| ENV Variable Name | Required/Optional | Type | Description | Accepted Values |
|---|---|---|---|---|
| VITE_APP_API_BASE_URL | Required | string |
Base URL of server | {host}/api/v1 |
| VITE_APP_LOG_LEVEL | Optional | string |
Log level | "none"|"error" | "warn" | |
| VITE_APP_DEMO | Optional | boolean |
Demo server or not | true|false | |
Sample ENV file:
VITE_APP_API_BASE_URL="http://localhost:5000/api/v1"
VITE_APP_LOG_LEVEL="debug"
Starting the Client development server
- Run
npm run devto start the development server.
Server Installation
- Change the directory to the
Serverdirectory - Install all dependencies by running
npm install - Add a
.envfile to theServerdirectory with the following options:
Environment variables
Configure the server with the following environmental variables:
| ENV Variable Name | Required/Optional | Type | Description | Accepted Values |
|---|---|---|---|---|
| CLIENT_HOST | Required | string | Frontend Host | |
| JWT_SECRET | Required | string | JWT secret | |
| REFRESH_TOKEN_SECRET | Required | string | Refresh JWT secret | |
| DB_TYPE | Optional | string | Specify DB to use | MongoDB | FakeDB |
| DB_CONNECTION_STRING | Required | string | Specifies URL for MongoDB Database | |
| PORT | Optional | integer | Specifies Port for Server | |
| LOGIN_PAGE_URL | Required | string | Login url to be used in emailing service | |
| REDIS_HOST | Required | string | Host address for Redis database | |
| REDIS_PORT | Required | integer | Port for Redis database | |
| TOKEN_TTL | Optional | string | Time for token to live | In vercel/ms format https://github.com/vercel/ms |
| REFRESH_TOKEN_TTL | Optional | string | Time for refresh token to live | |
| PAGESPEED_API_KEY | Optional | string | API Key for PageSpeed requests | |
| SYSTEM_EMAIL_HOST | Required | string | Host to send System Emails From | |
| SYSTEM_EMAIL_PORT | Required | number | Port for System Email Host | |
| SYSTEM_EMAIL_ADDRESS | Required | string | System Email Address | |
| SYSTEM_EMAIL_PASSWORD | Required | string | System Email Password |
Sample env file
CLIENT_HOST="http://localhost:5173"
JWT_SECRET="my_secret"
DB_TYPE="MongoDB"
DB_CONNECTION_STRING="mongodb://localhost:27017/uptime_db"
REDIS_HOST="127.0.0.1"
REDIS_PORT=6379
TOKEN_TTL="99d"
PAGESPEED_API_KEY=<api_key>
SYSTEM_EMAIL_HOST="smtp.gmail.com"
SYSTEM_EMAIL_PORT=465
SYSTEM_EMAIL_ADDRESS=<email_address>
SYSTEM_EMAIL_PASSWORD=<password>
REFRESH_TOKEN_SECRET="my_refresh"
REFRESH_TOKEN_TTL="99d"
Databases
This project requires two databases:
- Main application database: The project uses MongoDB for its primary database, with a MongoDB Docker image provided for easy setup.
- Redis for queue management: A Redis database is used for the PingService’s queue system, and a Redis Docker image is included for deployment.
You may use the included Dockerfiles to spin up databases quickly if you wish.
(Optional) Dockerised databases
Dockerfiles for the server and databases are located in the Docker directory
MongoDB Image
Location: Docker/mongoDB.Dockerfile
The Docker/mongo/data directory should be mounted to the MongoDB container in order to persist data.
From the Docker directory run
- Build the image:
docker build -f mongoDB.Dockerfile -t uptime_database_mongo . - Run the docker image:
docker run -d -p 27017:27017 -v $(pwd)/mongo/data:/data/db --name uptime_database_mongo uptime_database_mongo
Redis Image
Location Docker/redis.Dockerfile
the Docker/redis/data directory should be mounted to the Redis container in order to persist data.
From the Docker directory run
- Build the image:
docker build -f redis.Dockerfile -t uptime_redis . - Run the image:
docker run -d -p 6379:6379 -v $(pwd)/redis/data:/data --name uptime_redis uptime_redis
Starting the development server
- run
npm run devto start the development server
or,
- run
node index.jsto start server
API documentation
Our API is documented in accordance with the OpenAPI spec.
You can see the documentation on your local development server at http://localhost:{port}/api-docs
You can also view the documentation on our demo server at https://uptime-demo.bluewavelabs.ca/api-docs
Error handling
Errors are returned in a standard format:
{"success": false, "msg": "No token provided"}
Errors are handled by error handling middleware and should be thrown with the following parameters
| Name | Type | Default | Notes |
|---|---|---|---|
| status | integer |
500 | Standard HTTP codes |
| message | string |
"Something went wrong" | An error message |
| service | string |
"Unknown Service" | Name of service that threw the error |
Example:
const myRoute = async(req, res, next) => {
try{
const result = myRiskyOperationHere();
}
catch(error){
error.status = 404
error.message = "Resource not found"
error.service = service name
next(error)
return;
}
}
Errors should not be handled at the controller level and should be left to the middleware to handle.