Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
NODE_ENV=PROD

API_PORT=3000

DB_USER=bennu
DB_PASS=root
DB_HOST=mongodb
DB_PORT=27017
DB_NAME=bennuBR

TOKEN_SECRET=@okashj9-230ursakjdk@spojpaos
TOKEN_EXPIRES=1d
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# compiled output
/dist
/node_modules

ormconfig.js

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
yarn.lock

# IDEs and editors
*.launch
.settings/

# Environment
# .env

# Optional npm cache directory
.npm
package-lock.json
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debugger: Integraded Terminal",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"dev"
],
"console": "integratedTerminal"
}
]
}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:14-alpine
WORKDIR "/app"
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
131 changes: 99 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,99 @@
# Desafio BennuBR de Backend

Contrua uma API em NodeJS, que consultará o arquivo _news.json_ e disponibilizará as seguintes rotas:

- Rota para Login, retornando o _JWT_ que será utilizado nas requisições;
- Rota para Logout (rota autenticada com _JWT_);
- Rota para listar notícias (rota autenticada com _JWT_) no formato _JSON_;
- Rota para exibir o detalhe de uma notícia através do _ID_ (rota autenticada com _JWT_) no formato _JSON_;

## Requisitos
- Forkar esse desafio e criar o seu projeto (ou workspace) usando a sua versão desse repositório, tão logo acabe o desafio, submeta um pull request.
- O código precisa rodar em macOS ou Ubuntu (preferencialmente como container Docker)
- Para executar seu código, deve ser preciso apenas rodar os seguintes comandos:
- git clone \$seu-fork
- cd \$seu-fork
- comando para instalar dependências
- comando para executar a aplicação
- A API pode ser escrita com ou sem a ajuda de _frameworks_
- Se optar por usar um _framework_ que resulte em _boilerplate code_, assinale no README qual pedaço de código foi escrito por você. Quanto mais código feito por você, mais conteúdo teremos para avaliar.
- A API precisa suportar um volume de 1000 requisições por segundo em um teste de estresse.

## Critério de avaliação

- **Organização do código**
- **Clareza**
- **Assertividade**
- **Legibilidade do código**
- **Segurança**
- **Histórico de commits**
- **Escolhas técnicas**

Boa sorte e divirta-se!!!
# BennuBR Backend Challenge

### About
This project is a news API, where authenticated users can get information about news stored in the database.


### Tools
To make this possible, this project uses NodeJs with Express, MongoDB database, mongose to manage requests to the database, authentication with JWT Web Token. Everything running in a Docker container, using docker compose, building te API with PM2 in a Docker instance.

---
### Requirements


To use this project, you must have installed:

- Docker
- Docker-Compose

or:

- NodeJs
- MongoDB


## Starting
First of all, clone this repositorie running:

```
git clone git@github.com:fellipehfa/desafio-backend.git
cd desafio-backend
```

### Using Docker and docker-compose

Running with all logs:

```
docker-compose up
```

Running with out loock your terminal:
```
docker-compose up -d
```
To see the logs on dokcer container:
```
docker-compose logs -f
```
To build the container again:
```
docker-compose up --build
```

If everything went well, you will see logs like that:
```
node_api | 19:25:09 0|server | Server's running on port 3000! ⚡️⚡️⚡️⚡️
node_api | 19:25:09 0|server | http://localhost:3000
node_api | 19:25:09 0|server | Successfully connected to the database 🤓
```

### Using NodeJS and MongoDB (Local)

Set the constante NODE_ENV to DEV on dotFile (.env).
Install the dependencies running:
```
npm install
```
After that, just run:
```
npm run dev
```
If everything went well, you will see logs like that:
```
Server's running on port 3000! ⚡️⚡️⚡️⚡️
http://localhost:3000
Successfully connected to the database 🤓
```

## Testing
Download the request template by clicking on the link below and importing it into your Postman:

https://www.getpostman.com/collections/86cd998e8daf98c596e9

File > Import > Link and enter with this link.

OR

Download the JSON file here:
https://github.com/fellipehfa/desafio-backend/tree/master/doc

And import to your Postman

File > Import > File > Upload file and selecting the JSON file.


## Errors
Make sure the ports used are available, if necessary, you can change the ports in the dotEnv (.env) file.

Enter the generated Token in your Postman environment or manually configure it in the request headers.
196 changes: 196 additions & 0 deletions doc/BennuTV.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
"info": {
"_postman_id": "bbc49683-bbe6-49f6-9e2d-2365507604f0",
"name": "BennuTV",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "17256493"
},
"item": [
{
"name": "NEWS",
"item": [
{
"name": "List",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": " Bearer {{TOKEN}}",
"type": "text"
}
],
"url": {
"raw": "http://localhost:3000/news",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"news"
],
"query": [
{
"key": "id",
"value": "782973",
"disabled": true
}
]
}
},
"response": []
},
{
"name": "Get",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": " Bearer {{TOKEN}}",
"type": "text"
}
],
"url": {
"raw": "http://localhost:3000/news/782476",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"news",
"782476"
]
}
},
"response": []
},
{
"name": "Store",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": " Bearer {{TOKEN}}",
"type": "text"
}
],
"url": {
"raw": "http://localhost:3000/news/",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"news",
""
]
}
},
"response": []
}
]
},
{
"name": "USERS",
"item": [
{
"name": "Store",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"cacau@dev.com\",\n \"password\": \"1234\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/user/",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"user",
""
]
}
},
"response": []
}
]
},
{
"name": "AUTH",
"item": [
{
"name": "Login",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"cacau@dev.com\",\n \"password\": \"1234\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/auth/login",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"auth",
"login"
]
}
},
"response": []
},
{
"name": "Logout",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"cacau@dev.com\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/auth/logout",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"auth",
"logout"
]
}
},
"response": []
}
]
}
]
}
Loading