serverest 2.27.0-beta.1 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env ADDED
@@ -0,0 +1 @@
1
+ MOESIF_APPLICATION_ID=eyJhcHAiOiIxNTA6MTU1MCIsInZlciI6IjIuMCIsIm9yZyI6IjQ5MToxMTIxIiwiaWF0IjoxNjg4MTY5NjAwfQ.REWsfoWiqfL9quQ97X0VPO8xI-jKZR24k3nSmAgJ1ss
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  <a href="https://github.com/ServeRest/ServeRest/blob/trunk/.github/CODE_OF_CONDUCT.md">Código de conduta</a> |
16
16
  <a href="https://github.com/ServeRest/ServeRest/blob/trunk/.github/CONTRIBUTING.md">Como contribuir</a> |
17
17
  <a href="https://github.com/ServeRest/ServeRest/blob/trunk/CHANGELOG.md">Histórico de alterações</a> |
18
- <a href="https://github.com/ServeRest/ServeRest#patrocinadores">Patrocinadores</a>
18
+ <a href="https://github.com/ServeRest/ServeRest#doadores">Doadores</a>
19
19
  </b>
20
20
  </p>
21
21
 
@@ -29,7 +29,6 @@ _ServeRest_ permite o estudo de:
29
29
  - Autenticação no header
30
30
  - Query string
31
31
  - Teste de schema json
32
- - Teste de carga
33
32
 
34
33
  <b><h2 align="center">Ambientes disponíveis</h2></b>
35
34
 
@@ -129,10 +128,9 @@ Você pode encontrar as versões disponíveis na [lista de tags no Docker Hub](h
129
128
 
130
129
  ### IMPORTANTE
131
130
 
132
- 1. É obrigatório enviar o header `monitor: false` em todas as requisições do seu teste de carga.
133
- 2. O teste de carga deve ser executado apenas em ambiente local (disponibilizado via [NPM](#localmente-com-npm) ou [Docker](#localmente-com-docker) e acessível via <http://localhost:3000>).
131
+ **O teste de carga deve ser executado apenas em ambiente local (disponibilizado via [NPM](#localmente-com-npm) ou [Docker](#localmente-com-docker) e acessível via <http://localhost:3000>).**
134
132
 
135
- > O não seguimento dos 2 tópicos acimas vai acarretar em prejuízo para o projeto open source e gratuito e irá impactar o estudo de outras pessoas.
133
+ > O não seguimento vai acarretar em prejuízo para o projeto open source e gratuito e irá impactar o estudo de outras pessoas.
136
134
 
137
135
  ### Acesso ao status
138
136
 
@@ -170,17 +168,15 @@ Os repositórios abaixo são exemplos de automação com boas práticas e que co
170
168
 
171
169
  Para encontrar mais repositórios acesse https://github.com/search?q=serverest&type=Repositories
172
170
 
173
- ## Patrocinadores
171
+ ## Doadores
174
172
 
175
- ### Empresas ($15+/mês)
173
+ Achou o projeto útil? Faça doação única ou mensal a partir de 1 dólar e ajude a pagar o domínio, a hospedagem e a manutenção de <https://serverest.dev>.
176
174
 
177
- Sua empresa usa o ServeRest? Pergunte ao seu gerente ou equipe de marketing se sua empresa estaria interessada em apoiar este projeto e ter os seguintes serviços:
178
- 1. Subdomínio próprio (_nome-escolhido.serverest.dev_)
179
- 1. Acesso a todas as requests e respostas feitas nos últimos 7 dias no subdomínio
175
+ Pessoas que apoiam o ServeRest:
180
176
 
181
- [![Empresas - Open Collective](https://opencollective.com/serverest/tiers/patrocinador.svg)](https://opencollective.com/serverest)
177
+ [![Apoiador individual - Open Collective](https://opencollective.com/serverest/tiers/apoiador.svg)](https://opencollective.com/serverest)
182
178
 
183
- Empresas que apoiam o ServeRest:
179
+ Empresas que apoiam o ServeRest financeiramente:
184
180
 
185
181
  <p align="center">
186
182
  <img alt="Logo da Compass Uol" src="https://user-images.githubusercontent.com/29241659/195455525-6d97e444-630e-45c6-92b9-50ea44f06590.png#gh-light-mode-only" height="80">
@@ -190,13 +186,20 @@ Empresas que apoiam o ServeRest:
190
186
  <img alt="Logo da Agilizei" src="https://user-images.githubusercontent.com/29241659/177436678-8187f90f-bb4a-4978-87ab-a03f2f80820f.png" height="124">
191
187
  </p>
192
188
 
193
- ### Individuais
189
+ Todos os apoiadores anteriores e atuais podem ser vistos no [Open Collective do ServeRest](https://opencollective.com/serverest#section-contributors).
194
190
 
195
- Achou o projeto útil? Faça doação única ou mensal a partir de 1 dólar e ajude a pagar o domínio, a hospedagem e a manutenção de <https://serverest.dev>.
191
+ ### Patrocínio com produtos
196
192
 
197
- [![Apoiador individual - Open Collective](https://opencollective.com/serverest/tiers/apoiador.svg)](https://opencollective.com/serverest)
193
+ ServeRest é apoiado pelas seguintes empresas, que fornecem acesso aos seus produtos através de plano de apoio a projetos open source:
198
194
 
199
- Todos os patrocinadores anteriores e atuais podem ser vistos no [Open Collective do ServeRest](https://opencollective.com/serverest#section-contributors).
195
+ <p align="center">
196
+ <a href="https://www.datadoghq.com/">
197
+ <img alt="Logo do Datadog" src="https://github.com/ServeRest/ServeRest/assets/29241659/6d63a41e-aa98-428d-98ed-8670e6c9aff8" height="100">
198
+ </a>
199
+ <a href="https://1password.com/">
200
+ <img alt="Logo do 1password" src="https://github.com/ServeRest/ServeRest/assets/29241659/777347a3-b616-44ef-b089-c257759d96c0" height="80">
201
+ </a>
202
+ </p>
200
203
 
201
204
  ## Contribuidores ✨
202
205
 
@@ -206,23 +209,26 @@ Veja aqui [como você pode contribuir](https://github.com/ServeRest/ServeRest/bl
206
209
  <!-- prettier-ignore-start -->
207
210
  <!-- markdownlint-disable -->
208
211
  <table>
209
- <tr>
210
- <td align="center"><a href="https://github.com/leandromuto"><img src="https://avatars0.githubusercontent.com/u/1757827?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Leandro Muto</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=leandromuto" title="Documentation">📖</a> <a href="#infra-leandromuto" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
211
- <td align="center"><a href="https://github.com/fejsrodrigues"><img src="https://avatars3.githubusercontent.com/u/8000936?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Felipe Rodrigues</b></sub></a><br /><a href="#infra-fejsrodrigues" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
212
- <td align="center"><a href="https://github.com/doamaral"><img src="https://avatars0.githubusercontent.com/u/7451330?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lucas Amaral</b></sub></a><br /><a href="#talk-doamaral" title="Talks">📢</a> <a href="https://github.com/ServeRest/ServeRest/issues?q=author%3Adoamaral" title="Bug reports">🐛</a> <a href="https://github.com/ServeRest/ServeRest/commits?author=doamaral" title="Documentation">📖</a></td>
213
- <td align="center"><a href="https://www.linkedin.com/in/ulucasfraga/"><img src="https://avatars2.githubusercontent.com/u/23031781?v=4?s=100" width="100px;" alt=""/><br /><sub><b>lucas.fraga</b></sub></a><br /><a href="#ideas-uLucasFraga" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ServeRest/ServeRest/issues?q=author%3AuLucasFraga" title="Bug reports">🐛</a></td>
214
- <td align="center"><a href="https://www.linkedin.com/in/bruno-batista-87734464/?locale=en_US"><img src="https://avatars3.githubusercontent.com/u/8673550?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bruno batista</b></sub></a><br /><a href="#ideas-brunobatista25" title="Ideas, Planning, & Feedback">🤔</a></td>
215
- <td align="center"><a href="https://github.com/eliasreis54"><img src="https://avatars1.githubusercontent.com/u/29265526?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elias Reis</b></sub></a><br /><a href="#maintenance-eliasreis54" title="Maintenance">🚧</a> <a href="#infra-eliasreis54" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
216
- <td align="center"><a href="https://github.com/gabriel-pinheiro"><img src="https://avatars2.githubusercontent.com/u/56726395?v=4?s=100" width="100px;" alt=""/><br /><sub><b>gabriel-pinheiro</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=gabriel-pinheiro" title="Code">💻</a> <a href="#ideas-gabriel-pinheiro" title="Ideas, Planning, & Feedback">🤔</a></td>
217
- </tr>
218
- <tr>
219
- <td align="center"><a href="http://gomex.me"><img src="https://avatars3.githubusercontent.com/u/95132?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rafael Gomes</b></sub></a><br /><a href="#infra-gomex" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
220
- <td align="center"><a href="https://about.me/rustnnes"><img src="https://avatars1.githubusercontent.com/u/638445?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Diego Bandeira</b></sub></a><br /><a href="#infra-rustnnes" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
221
- <td align="center"><a href="https://github.com/maximilianoalves"><img src="https://avatars3.githubusercontent.com/u/11561118?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maximiliano Alves</b></sub></a><br /><a href="#talk-maximilianoalves" title="Talks">📢</a></td>
222
- <td align="center"><a href="https://github.com/murilomaiaa"><img src="https://avatars.githubusercontent.com/u/56596799?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Murilo Maia</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=murilomaiaa" title="Code">💻</a></td>
223
- <td align="center"><a href="https://github.com/crisnazario"><img src="https://avatars.githubusercontent.com/u/37200398?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Cristina Nazário</b></sub></a><br /><a href="#ideas-crisnazario" title="Ideas, Planning, & Feedback">🤔</a></td>
224
- <td align="center"><a href="http://www.eduardosantos.dev"><img src="https://avatars.githubusercontent.com/u/10568807?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Eduardo Santos</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=edumaxsantos" title="Code">💻</a></td>
225
- </tr>
212
+ <tbody>
213
+ <tr>
214
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/leandromuto"><img src="https://avatars0.githubusercontent.com/u/1757827?v=4?s=100" width="100px;" alt="Leandro Muto"/><br /><sub><b>Leandro Muto</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=leandromuto" title="Documentation">📖</a> <a href="#infra-leandromuto" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
215
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/fejsrodrigues"><img src="https://avatars3.githubusercontent.com/u/8000936?v=4?s=100" width="100px;" alt="Felipe Rodrigues"/><br /><sub><b>Felipe Rodrigues</b></sub></a><br /><a href="#infra-fejsrodrigues" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
216
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/doamaral"><img src="https://avatars0.githubusercontent.com/u/7451330?v=4?s=100" width="100px;" alt="Lucas Amaral"/><br /><sub><b>Lucas Amaral</b></sub></a><br /><a href="#talk-doamaral" title="Talks">📢</a> <a href="https://github.com/ServeRest/ServeRest/issues?q=author%3Adoamaral" title="Bug reports">🐛</a> <a href="https://github.com/ServeRest/ServeRest/commits?author=doamaral" title="Documentation">📖</a></td>
217
+ <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/ulucasfraga/"><img src="https://avatars2.githubusercontent.com/u/23031781?v=4?s=100" width="100px;" alt="lucas.fraga"/><br /><sub><b>lucas.fraga</b></sub></a><br /><a href="#ideas-uLucasFraga" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ServeRest/ServeRest/issues?q=author%3AuLucasFraga" title="Bug reports">🐛</a></td>
218
+ <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/bruno-batista-87734464/?locale=en_US"><img src="https://avatars3.githubusercontent.com/u/8673550?v=4?s=100" width="100px;" alt="bruno batista"/><br /><sub><b>bruno batista</b></sub></a><br /><a href="#ideas-brunobatista25" title="Ideas, Planning, & Feedback">🤔</a></td>
219
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/eliasreis54"><img src="https://avatars1.githubusercontent.com/u/29265526?v=4?s=100" width="100px;" alt="Elias Reis"/><br /><sub><b>Elias Reis</b></sub></a><br /><a href="#maintenance-eliasreis54" title="Maintenance">🚧</a> <a href="#infra-eliasreis54" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
220
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/gabriel-pinheiro"><img src="https://avatars2.githubusercontent.com/u/56726395?v=4?s=100" width="100px;" alt="gabriel-pinheiro"/><br /><sub><b>gabriel-pinheiro</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=gabriel-pinheiro" title="Code">💻</a> <a href="#ideas-gabriel-pinheiro" title="Ideas, Planning, & Feedback">🤔</a></td>
221
+ </tr>
222
+ <tr>
223
+ <td align="center" valign="top" width="14.28%"><a href="http://gomex.me"><img src="https://avatars3.githubusercontent.com/u/95132?v=4?s=100" width="100px;" alt="Rafael Gomes"/><br /><sub><b>Rafael Gomes</b></sub></a><br /><a href="#infra-gomex" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
224
+ <td align="center" valign="top" width="14.28%"><a href="https://about.me/rustnnes"><img src="https://avatars1.githubusercontent.com/u/638445?v=4?s=100" width="100px;" alt="Diego Bandeira"/><br /><sub><b>Diego Bandeira</b></sub></a><br /><a href="#infra-rustnnes" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
225
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/maximilianoalves"><img src="https://avatars3.githubusercontent.com/u/11561118?v=4?s=100" width="100px;" alt="Maximiliano Alves"/><br /><sub><b>Maximiliano Alves</b></sub></a><br /><a href="#talk-maximilianoalves" title="Talks">📢</a></td>
226
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/murilomaiaa"><img src="https://avatars.githubusercontent.com/u/56596799?v=4?s=100" width="100px;" alt="Murilo Maia"/><br /><sub><b>Murilo Maia</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=murilomaiaa" title="Code">💻</a></td>
227
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/crisnazario"><img src="https://avatars.githubusercontent.com/u/37200398?v=4?s=100" width="100px;" alt="Cristina Nazário"/><br /><sub><b>Cristina Nazário</b></sub></a><br /><a href="#ideas-crisnazario" title="Ideas, Planning, & Feedback">🤔</a></td>
228
+ <td align="center" valign="top" width="14.28%"><a href="http://www.eduardosantos.dev"><img src="https://avatars.githubusercontent.com/u/10568807?v=4?s=100" width="100px;" alt="Eduardo Santos"/><br /><sub><b>Eduardo Santos</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=edumaxsantos" title="Code">💻</a></td>
229
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/RenatoDaM"><img src="https://avatars.githubusercontent.com/u/112330702?v=4?s=100" width="100px;" alt="Renato Davoli"/><br /><sub><b>Renato Davoli</b></sub></a><br /><a href="https://github.com/ServeRest/ServeRest/commits?author=RenatoDaM" title="Code">💻</a></td>
230
+ </tr>
231
+ </tbody>
226
232
  </table>
227
233
 
228
234
  <!-- markdownlint-restore -->
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "serverest",
3
- "version": "2.27.0-beta.1",
3
+ "version": "2.27.0",
4
4
  "description": "Servidor REST local de forma rápida e simples para estudo de testes de API",
5
- "author": "Paulo Gonçalves <paulorochag@hotmail.com> (https://www.linkedin.com/in/paulo-goncalves/)",
5
+ "author": "Paulo Gonçalves <author@serverest.dev> (https://www.linkedin.com/in/paulo-goncalves/)",
6
6
  "license": "GPL-3.0",
7
7
  "main": "./src/server.js",
8
8
  "bin": {
9
9
  "serverest": "src/server.js"
10
10
  },
11
11
  "files": [
12
+ ".env",
12
13
  "docs/",
13
14
  "src/"
14
15
  ],
@@ -49,7 +50,9 @@
49
50
  "colors": "^1.4.0",
50
51
  "connect-timeout": "^1.9.0",
51
52
  "cors": "^2.8.5",
53
+ "dd-trace": "^4.14.0",
52
54
  "debug": "^4.3.4",
55
+ "dotenv": "^16.3.1",
53
56
  "express": "^4.17.1",
54
57
  "express-async-errors": "^3.1.1",
55
58
  "express-query-int": "^3.0.0",
@@ -61,7 +64,6 @@
61
64
  "morgan": "^1.10.0",
62
65
  "nedb-promises": "^5.0.0",
63
66
  "open": "^8.0.6",
64
- "rate-limiter-flexible": "^2.3.1",
65
67
  "swagger-ui-express": "^4.1.4",
66
68
  "yargs": "^16.2.0"
67
69
  },
package/src/app.js CHANGED
@@ -9,20 +9,29 @@ const queryParser = require('express-query-int')
9
9
  const timeout = require('connect-timeout')
10
10
  const { join } = require('path')
11
11
  const swaggerUi = require('swagger-ui-express')
12
-
13
- const { aplicacaoExecutandoLocalmente, formaDeExecucao, urlDocumentacao } = require('./utils/ambiente')
12
+ const ddTrace = require('dd-trace')
13
+
14
+ const {
15
+ aplicacaoExecutandoLocalmente,
16
+ formaDeExecucao,
17
+ urlDocumentacao,
18
+ ehAmbienteDeTestes
19
+ } = require('./utils/ambiente')
14
20
  const { conf } = require('./utils/conf')
15
21
  const errorHandler = require('./middlewares/error-handler')
16
22
  const logger = require('./utils/logger')
17
23
  const { version } = require('../package.json')
18
24
  const swaggerDocument = require('../docs/swagger.json')
19
- const rateLimiter = require('./middlewares/rate-limiter')
20
25
  const packageJson = require('../package.json')
21
26
 
22
- const ehAmbienteDeTestes = process.env.NODE_ENV === 'serverest-test'
23
-
24
27
  const app = express()
25
28
 
29
+ /* istanbul ignore next */
30
+ if (formaDeExecucao() !== 'npm') {
31
+ ddTrace.init()
32
+ ddTrace.use('express')
33
+ }
34
+
26
35
  app.set('json spaces', 4)
27
36
  app.use(express.json())
28
37
  app.use(express.urlencoded({ extended: false }))
@@ -30,11 +39,6 @@ app.use(queryParser())
30
39
  app.use(timeout())
31
40
  app.use(cors())
32
41
 
33
- /* istanbul ignore next */
34
- if (!ehAmbienteDeTestes) {
35
- app.use(rateLimiter)
36
- }
37
-
38
42
  app.disable('etag')
39
43
 
40
44
  /* istanbul ignore else */
@@ -58,7 +58,7 @@ exports.concluirCompra = async (req, res) => {
58
58
  const carrinhoDoUsuario = await service.getCarrinhoDoUsuario(req.headers.authorization)
59
59
 
60
60
  if (carrinhoDoUsuario.length) {
61
- await service.concluiCompra(carrinhoDoUsuario)
61
+ await service.concluiCompra(carrinhoDoUsuario[0])
62
62
  return res.status(200).send({ message: constant.DELETE_SUCCESS })
63
63
  }
64
64
  res.status(200).send({ message: constant.NO_CART })
@@ -6,17 +6,30 @@ function errorHandler (error, _req, res, _next) {
6
6
  if (erroDeSchema) {
7
7
  return res.status(400).json(montarMensagemDeErroDeSchema(error))
8
8
  }
9
- /* istanbul ignore if */
9
+ // https://github.com/expressjs/body-parser#errors
10
10
  if (error.type === 'entity.parse.failed') {
11
- console.log('Erro 500')
12
- return res.status(500).json({
11
+ console.log('lOG - Entity parse error, user sending request without proper quotation marks.')
12
+ return res.status(400).json({
13
13
  message: 'Adicione aspas em todos os valores. Para mais informações acesse a issue https://github.com/ServeRest/ServeRest/issues/225'
14
14
  })
15
15
  }
16
+ if (error.type === 'entity.too.large') {
17
+ return res.status(413).json({ message: 'Payload too large' })
18
+ }
19
+ if (error.type === 'charset.unsupported') {
20
+ return res.status(415).json({ message: 'Unsupported charset', charset: error.charset })
21
+ }
16
22
  /* istanbul ignore if */
17
23
  if (error.code === 'ETIMEDOUT') {
18
24
  return res.status(408).json({ message: TIMEOUT })
19
25
  }
26
+
27
+ console.error('lOG - Error 500:', error)
28
+ console.error('lOG - Request:', _req)
29
+
30
+ if (error.type) {
31
+ return res.status(500).json({ message: INTERNAL_ERROR, error: error.type })
32
+ }
20
33
  return res.status(500).json({ message: INTERNAL_ERROR, error })
21
34
  }
22
35
 
package/src/server.js CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  'use strict'
4
4
 
5
+ const path = require('path')
6
+ require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
7
+
5
8
  const colors = require('colors')
6
9
  const debug = require('debug')('nodestr:server')
7
10
  const http = require('http')
@@ -3,17 +3,20 @@
3
3
  const { conf } = require('./conf')
4
4
 
5
5
  function formaDeExecucao () {
6
- if (process.env.USERNAME === 'docker' ||
7
- process.env.USERNAME === 'serverest.dev' ||
8
- process.env.USERNAME === 'staging.serverest.dev' ||
9
- process.env.USERNAME === 'agilizei' ||
10
- process.env.USERNAME === 'cesarschool' ||
11
- process.env.USERNAME === 'compassuol') {
12
- return process.env.USERNAME
6
+ if (process.env.ENVIRONMENT === 'docker' ||
7
+ process.env.ENVIRONMENT === 'serverest.dev' ||
8
+ process.env.ENVIRONMENT === 'staging.serverest.dev' ||
9
+ process.env.ENVIRONMENT === 'agilizei' ||
10
+ process.env.ENVIRONMENT === 'cesarschool' ||
11
+ process.env.ENVIRONMENT === 'compassuol') {
12
+ return process.env.ENVIRONMENT
13
13
  }
14
14
  return 'npm'
15
15
  }
16
16
 
17
+ const ehAmbienteDeTestes = process.env.NODE_ENV === 'serverest-test'
18
+ const ehAmbienteDeDesenvolvimento = process.env.NODE_ENV === 'serverest-development'
19
+
17
20
  const aplicacaoExecutandoLocalmente = () => {
18
21
  return (formaDeExecucao() === 'npm' || formaDeExecucao() === 'docker')
19
22
  }
@@ -38,5 +41,7 @@ function urlDocumentacao () {
38
41
  module.exports = {
39
42
  aplicacaoExecutandoLocalmente,
40
43
  formaDeExecucao,
41
- urlDocumentacao
44
+ urlDocumentacao,
45
+ ehAmbienteDeDesenvolvimento,
46
+ ehAmbienteDeTestes
42
47
  }
@@ -10,34 +10,33 @@ Esse arquivo está marcado para ser ignorado no arquivo stryker.conf.js
10
10
  const moesif = require('moesif-nodejs')
11
11
 
12
12
  const { version } = require('../../package.json')
13
- const { formaDeExecucao } = require('./ambiente')
14
-
15
- const ehAmbienteDeDesenvolvimento = process.env.NODE_ENV === 'serverest-development'
16
- const ehAmbienteDeTestes = process.env.NODE_ENV === 'serverest-test'
13
+ const {
14
+ aplicacaoExecutandoLocalmente,
15
+ formaDeExecucao,
16
+ ehAmbienteDeDesenvolvimento,
17
+ ehAmbienteDeTestes
18
+ } = require('./ambiente')
17
19
 
18
20
  module.exports = async app => {
19
- if (ehAmbienteDeDesenvolvimento || ehAmbienteDeTestes) {
21
+ if (ehAmbienteDeDesenvolvimento || ehAmbienteDeTestes || !aplicacaoExecutandoLocalmente()) {
20
22
  return
21
23
  }
22
24
  const { porta, timeout, nodoc, nobearer, nosec } = require('../server').argv
23
25
  const moesifMiddleware = moesif({
24
- applicationId: 'eyJhcHAiOiIxNTA6MTU1MCIsInZlciI6IjIuMCIsIm9yZyI6IjQ5MToxMTIxIiwiaWF0IjoxNTk4OTE4NDAwfQ.e0E6Qhz1o1Jjs5prulHDYEBlv0juruWs_btjq2mong8',
26
+ applicationId: process.env.MOESIF_APPLICATION_ID,
25
27
  identifyUser: (req, res) => { return formaDeExecucao() },
26
28
  identifyCompany: (req, res) => { return version },
27
29
  skip: (req, res) => {
28
30
  if (req.originalUrl === '/__messages__' ||
29
31
  req.originalUrl === '/favicon.ico' ||
30
32
  req.originalUrl === '/socket.io' ||
31
- req.originalUrl === '/version' ||
32
33
  req.originalUrl === '/swagger-ui.css' ||
33
34
  req.originalUrl === '/swagger-ui.css.map' ||
34
35
  req.originalUrl === '/swagger-ui-init.js' ||
35
36
  req.originalUrl === '/swagger-ui-standalone-preset.js' ||
36
37
  req.originalUrl === '/swagger-ui-standalone-preset.js.map' ||
37
38
  req.originalUrl === '/swagger-ui-bundle.js' ||
38
- req.originalUrl === '/swagger-ui-bundle.js.map' ||
39
- req.headers.monitor ||
40
- (formaDeExecucao() === 'serverest.dev' && req.originalUrl === '/')) {
39
+ req.originalUrl === '/swagger-ui-bundle.js.map') {
41
40
  return true
42
41
  }
43
42
  },
@@ -1,37 +0,0 @@
1
- /* istanbul ignore file */
2
-
3
- const { RateLimiterMemory } = require('rate-limiter-flexible')
4
-
5
- const { aplicacaoExecutandoLocalmente } = require('../utils/ambiente')
6
-
7
- const rateLimiter = new RateLimiterMemory({
8
- points: 450, // requests
9
- duration: 30 // segundo por IP
10
- })
11
-
12
- // Irá retornar mensagem de erro se o teste de carga:
13
- // 1. Estiver sendo executado em localhost sem o header 'monitor'.
14
- // 2. Estiver sendo executado fora de localhost.
15
- module.exports = async (req, res, next) => {
16
- const reqContainsHeaderMonitor = req.rawHeaders.includes('monitor')
17
-
18
- const messageLoadTest = 'Foi detectado comportamento equivalente a teste de carga'
19
- const messageAdjust = 'Leia a seção sobre teste de carga https://github.com/ServeRest/ServeRest#teste-de-carga e faça o ajuste necessário.'
20
-
21
- await rateLimiter.consume(req.ip)
22
- .then(() => next())
23
- .catch(() => {
24
- if (aplicacaoExecutandoLocalmente()) {
25
- if (!reqContainsHeaderMonitor) {
26
- return res.status(429).send({
27
- message: `${messageLoadTest} com ausência do header 'monitor'. ${messageAdjust}`
28
- })
29
- }
30
- } else {
31
- return res.status(429).send({
32
- message: `${messageLoadTest}. ${messageAdjust}`
33
- })
34
- }
35
- next()
36
- })
37
- }