Skip to content

andersoncgiusti/web

Repository files navigation

web

Project from collecting tags of links.

Executing

# Clone repository
git clone 

# Access file
cd web

# Copy the .env.example file and put the correct environment variables in the .env
cp .env.example .env

# Instale as dependΓͺncias
npm install

# Run project 
npm start or node server.js

# Run project test
npm test 

Create account MongoDB free

https://www.mongodb.com/

Components

# Database
MongoDB

# Librarys used
- @types/jest
- cheerio
- dotenv
- express
- jest
- mongoose
- node-fetch
- supertest

Project comportament

Endpoint generic: http://localhost:3000/

Method Description
/api/status/status() Test the status from project
/api/status/status_test() To test in unit test
/api/books/books_status() Test the status from route
/api/books/booksPostUrl() Get the link: http://books.toscrape.com/catalogue/page-1.html and save it to the database
/api/books/booksGetUrl() Search all data saved in the database
/api/pilots/pilots_status() Test the status from route
/api/pilots/pilotsPostUrl() Get the link: https://www.formula1.com/en/drivers.html and save it to the database
/api/pilots/pilotsGetUrl() Search all data saved in the database

Example of response

Method GET /api/status/status()

{
    "author": "Anderson Giusti"
}

Method GET /api/books/booksGetUrl()

{
    "message": "Consulting books with successfully!",
    "books": [
        {
            "_id": "636935bca457f6f4a80a63ee",
            "link_image": "http://books.toscrape.com/media/cache/2c/da/2cdad67c44b002e7ead0cc35693c0e8b.jpg",
            "link_catalogue": "http://books.toscrape.coma-light-in-the-attic_1000/index.html",
            "created_at": "2022-11-07T16:43:40.096Z",
            "__v": 0
        },
    ]
}

Method GET /api/books/books_status()

{
    "success": true
}

Method GET /api/pilots/pilotsGetUrl()

{
    "message": "Consulting pilots with successfully!",
    "pilots": [
        {
            "_id": "636935a6a457f6f4a80a63c2",
            "photo": "https://www.formula1.com/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/2col/image.png",
            "link": "https://www.formula1.com/en/drivers/max-verstappen.html",
            "created_at": "2022-11-07T16:43:18.308Z",
            "__v": 0
        },
    ]
}

Method GET /api/books/pilots_status()

{
    "success": true
}

Architecture

server.js

Node.js server, used the routes, converted the data to Json and made connection with db.

.env

Managed the MongoDb configuration environment variable.

πŸ“‚ src

πŸ“‚ routes

Created the routes only with the responsibility of the HTTP methods.

πŸ“‚ controllers

Created the logic and saved the db information.

πŸ“‚ model

Modeled the data schema for the bank.

πŸ“‚ test

Unit test.


 πŸ“ web
   |
   |-  πŸ“ src
   |    |   |
   |    |- πŸ“ controllers
   |         |- πŸ“„ books.controller.js
   |         |- πŸ“„ pilots.controler.js
   |         |- πŸ“„ status.controler.js
   |
   |    |- πŸ“ models
   |         |- πŸ“„ books.model.js
   |         |- πŸ“„ pilots.model.js
   |
   |    |- πŸ“ routes
   |         |- πŸ“„ books.router.js 
   |         |- πŸ“„ pilots.router.js 
   |         |- πŸ“„ status.router.js 
   |       |- πŸ“„ app.js 
   |-  πŸ“ test
   |     |- πŸ“„ books.test.js
   |     |- πŸ“„ pilots.test.js
   |     |- πŸ“„ server.test.js
   |     |- πŸ“„ status.test.js
   |
   |- πŸ“„ .dockerignore
   |- πŸ“„ .env
   |- πŸ“„ .env.example
   |- πŸ“„ .gitignore
   |- πŸ“„ Dockerfile
   |- πŸ“„ jest.config.js
   |- πŸ“„ package
   |- πŸ“„ server.js

Cloud

Create account IBM Cloud free

https://cloud.ibm.com/login 

Kubernets

With plan lite in IBM Cloud, create cluster free for 30 days

Container Registry

Create a container registry following docs

https://cloud.ibm.com/registry/start

Configure Cluster via CLI

ibmcloud login -a cloud.ibm.com -r eu-de -g Default
ibmcloud ks cluster config --cluster cdkg45mf0fj1ue2md1d0
kubectl config current-context

Resources installed link whith image

https://drive.google.com/file/d/1BmMPf2zim1oBbigiyChXKX4KlEAg1gt2/view
https://drive.google.com/file/d/1xywLhRlwi6zhy8F-KpPnxHDyUTcIMCuu/view?usp=share_link

Build project

Generate image installing all packages and dependencies: example

docker built -t br.icr.io/<my_namespace>/<my_repository>:<my_tag> .

Sending image to repository: example

docker push br.icr.io/<my_namespace>/<my_repository>:<my_tag>

Project runnig in cluster

https://drive.google.com/file/d/1W_t8NoMHIBJmlXMjb5CZufQzukBs9CM7/view?usp=share_link

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published