Skip to content

Commit

Permalink
chore: add debug option to make it easier to fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloGoncalvesBH committed May 3, 2024
1 parent 1eacc0f commit 91a24a5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Você pode contribuir de várias maneiras, sendo as mais conhecidas as seguintes

## Sumário
- [Execução do projeto](#execução-do-projeto)
- [Debug](#debug)
- [Etapas para contribuir](#etapas-para-contribuir)
- [Garantindo a qualidade do projeto](#garantindo-a-qualidade-do-projeto)
- [Legenda](#legenda)
Expand Down Expand Up @@ -73,6 +74,22 @@ Utilize o seguinte comando para executar o projeto enquanto desenvolve para util
make run-dev
```

### Debug

Para realizar o debug da aplicação com _VS Code_ há 2 maneiras:

1. **Debugando a aplicação em container Docker**: Utilize o comando `make run-debug` e na aba `Run and Debug` do VS Code selecione a opção `Docker: Attach to ServeRest container`.
2. **Debugando a aplicação localmente com NPM**: Na aba `Run and Debug` do VS Code selecione a opção `Launch via NPM`.

Escolha a forma de execução de acordo com o cenário que quer debugar.

Utilize a primeira opção se o erro ocorre em:
- Docker localmente.
- _serverest.dev_.

Utilize a segunda opção se o erro ocorre em:
- NPM localmente.

## Etapas para contribuir

1. [Fork](https://help.github.com/articles/fork-a-repo/) este repositório para sua própria conta GitHub, [clone](https://help.github.com/articles/cloning-a-repository/) no seu computador e, em seguida, acesse o diretório criado;
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ coverage.lcov

## Mac crap
.DS_Store
.vscode/

## Others
.env
Expand Down
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// 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": "Launch via NPM",
"request": "launch",
"runtimeArgs": [
"run",
"start"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**",
"${workspaceFolder}/node_modules/**/*.js",
],
"type": "node"
},
{
"name": "Docker: Attach to ServeRest container",
"type": "node",
"request": "attach",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app",
"skipFiles": [
"${workspaceFolder}/app/node_modules/**",
"/app/node_modules/**",
"<node_internals>/**",
],
}
]
}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# serverest

NAME_IMAGE=paulogoncalvesbh/serverest
HOST_PORT=3000

# COMANDOS PARA USAR A IMAGEM DE PRODUÇÃO \/

Expand All @@ -12,7 +11,7 @@ build:
@DOCKER_BUILDKIT=1 docker build --file Dockerfile --tag ${NAME_IMAGE} .

run:
@docker run -p ${HOST_PORT}:3000 ${NAME_IMAGE}
@docker run -p 3000:3000 ${NAME_IMAGE}

clean:
@docker rmi -f ${NAME_IMAGE}
Expand All @@ -25,6 +24,10 @@ stop:
run-dev:
@docker-compose up --abort-on-container-exit --build run-dev

run-debug:
docker build --file Dockerfile --tag serverest-debug .
docker run --entrypoint "npm" -p 3000:3000 -p 9229:9229 -v $(shell pwd):/app serverest-debug run start:debug

test-contract:
@docker-compose up --abort-on-container-exit --build test-contract

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"prepare": "is-ci || husky install",
"commit": "cz",
"start": "node ./src/server.js",
"start:debug": "node --inspect=0.0.0.0 ./src/server.js",
"dev": "nodemon --legacy-watch -e json,js ./src/server.js --nodoc",
"test:mutation": "stryker run ./test/stryker.conf.js",
"test:mutation:diff": "stryker-diff-runner --path ./test/stryker.conf.js --branch trunk",
Expand Down

0 comments on commit 91a24a5

Please sign in to comment.