Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub-Vacek committed Apr 4, 2020
0 parents commit 870d955
Show file tree
Hide file tree
Showing 60 changed files with 8,654 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/test
npm-debug.log
.dockerignore
/.idea
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/build
/dist
/.idea
/test
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:10
COPY package*.json ./
RUN npm install
COPY . .
ENV DOCKERIZE_VERSION v0.6.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

CMD dockerize -wait tcp://database:3306 -timeout 60m npm run start
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Description

Simple test server for monitoring urls. Uses MySql, Restify, Jest, TypeORM, Inversify.

# Structure
* authorization - service for token authorization

* database - database layer, every entity has its model and repository, DatabaseProvider provides entity repository for service layer

* http - simple axios service for getting responses from monitored endpoint url

* logger - simple winston logger

* monitor - monitor service handles monitoring of endpoint. Each instance of MonitoredJob is responsible for monitoring one monitored endpoint

* monitored-endpoint - monitored-endpoint service layer

* monitoring-result - monitoring-result service layer

* validation - services for monitored endpoint validation. Based on class-validator/class-transformer

* web - handles user interaction with server

* inversify.config - class responsible for configuration of Inversiy container

* app - application entrypoint

* server - represents application server

# Routes

* http://localhost:3000/monitored-endpoints - GET/POST - get/create monitored endpoint

* http://localhost:3000/monitored-endpoints - PUT/DELETE - update/delete monitored endpoint

* http://localhost:3000/monitored-endpoints/:id/monitoring-results/ - GET - get monitoring results from monitored endpoint with specified id

## Installation

```bash
npm install
```
## Build

```bash
npm run build
```

## Run

```bash
npm start
```

## Test

Basic unit tests using Jest
```bash
npm test
```

## Docker

```bash
docker-compose up -d
docker-compose up --build
```

## Curl

get monitored endpoints

```bash
curl -H "Authorization: Bearer 93f39e2f-80de-4033-99ee-249d92736a25" http://localhost:3000/monitored-endpoints
```

create monitored endpoint

```bash
curl -H "Authorization: Bearer 93f39e2f-80de-4033-99ee-249d92736a25" -H "Content-Type: application/json" -d '{"name": "test", "url": "http://private-264465-litackaapi.apiary-mock.com/cards/1/state", "monitoredInterval": 3}' http://localhost:3000/monitored-endpoints
```

update monitored endpoint

```bash
curl -X PUT -H "Authorization: Bearer 93f39e2f-80de-4033-99ee-249d92736a25" -H "Content-Type: application/json" -d '{"name": "test", "url": "http://private-264465-litackaapi.apiary-mock.com/cards/1/state", "monitoredInterval": 3}' http://localhost:3000/monitored-endpoints/1/
```

delete monitored endpoint

```bash
curl -X DELETE -H "Authorization: Bearer 93f39e2f-80de-4033-99ee-249d92736a25" -H "Content-Type: application/json" http://localhost:3000/monitored-endpoints/1/
```
get monitoring results

```bash
curl -H "Authorization: Bearer 93f39e2f-80de-4033-99ee-249d92736a25" http://localhost:3000/monitored-endpoints/1/monitoring-results

```
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'

services:
database:
image: "mysql:5.7"
container_name: "mysql"
ports:
- "3306:3306"
volumes:
- ./schema.sql:/docker-entrypoint-initdb.d/init.sql
expose:
- 3306
environment:
MYSQL_HOST: database
MYSQL_PORT: 3306
MYSQL_USERNAME: 'root'
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'applifting'

service:
build: .
image: "node"
container_name: "nodejs"
ports:
- "3000:3000"
depends_on:
- database
links:
- database
environment:
MYSQL_HOST: database
MYSQL_USERNAME: 'root'
MYSQL_PORT: 3306
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'applifting'
restart: on-failure


19 changes: 19 additions & 0 deletions error.log

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.ts?$': 'ts-jest',
},
testRegex: '(/__test__/.*|(\\.|/)(spec))\\.ts?$',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
testEnvironment: 'node'
};
Loading

0 comments on commit 870d955

Please sign in to comment.