Skip to content

Commit 34a367b

Browse files
committed
fix: envs
1 parent 1806136 commit 34a367b

File tree

8 files changed

+225
-168
lines changed

8 files changed

+225
-168
lines changed

.docker/.env.example

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
# docker
2-
COMPOSE_PROJECT_NAME=spring-boot-crud-containers
2+
COMPOSE_PROJECT_NAME=spring-boot-example-containers
33
TIMEZONE=America/Sao_Paulo
4+
API_PORT=8080
5+
API_DEBUG_PORT=8000
6+
APP_PORT=3000
47

58
# database
6-
DB_URL=database:5432/example_api
9+
DB_HOST=database
10+
DB_PORT=5432
11+
DB_NAME=example
712
DB_USERNAME=root
8-
DB_PASSWORD=root
13+
DB_PASSWORD=root
14+
DB_SHOW_SQL=true
15+
DB_MAX_CONNECTIONS=5
16+
17+
# security
18+
TOKEN_SECRET=secret
19+
TOKEN_EXPIRATION_IN_HOURS=24
20+
REFRESH_TOKEN_EXPIRATION_IN_DAYS=7
21+
MINUTES_TO_EXPIRE_RECOVERY_CODE=20
22+
MAX_REQUESTS_PER_MINUTE=20
23+
24+
# smtp
25+
SMTP_HOST=smtp.gmail.com
26+
SMTP_PORT=587
27+
SMTP_USERNAME=user@gmail
28+
SMTP_PASSWORD=secret
29+
30+
# swagger
31+
SWAGGER_URL=/docs

.docker/docker-compose.dev.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ services:
1414
"log_destination=stderr"
1515
]
1616
ports:
17-
- "5432:5432"
17+
- "${DB_PORT}:5432"
1818
environment:
1919
POSTGRES_USER: ${DB_USERNAME}
2020
POSTGRES_PASSWORD: ${DB_PASSWORD}
21-
POSTGRES_DB: example_api
22-
TZ: America/Sao_Paulo
23-
PGTZ: America/Sao_Paulo
21+
POSTGRES_DB: ${DB_NAME}
22+
TZ: ${TIMEZONE}
23+
PGTZ: ${TIMEZONE}
2424
volumes:
2525
- ./.volumes/database:/var/lib/postgresql/data
2626
networks:
27-
- simple-network
27+
- example-network
2828
tty: true
2929

3030
api:
@@ -34,20 +34,46 @@ services:
3434
links:
3535
- database
3636
ports:
37-
- "8080:8080"
38-
- "8000:8000"
37+
- "${API_PORT}:${API_PORT}"
38+
- "${API_DEBUG_PORT}:${API_DEBUG_PORT}"
3939
environment:
40-
DB_URL: ${DB_URL}
40+
41+
# database
42+
DB_PORT: ${DB_PORT}
43+
DB_NAME: ${DB_NAME}
44+
DB_HOST: ${DB_HOST}
4145
DB_USERNAME: ${DB_USERNAME}
4246
DB_PASSWORD: ${DB_PASSWORD}
47+
DB_SHOW_SQL: ${DB_SHOW_SQL}
48+
DB_MAX_CONNECTIONS: ${DB_MAX_CONNECTIONS}
49+
50+
# security
51+
TOKEN_SECRET: ${TOKEN_SECRET}
52+
TOKEN_EXPIRATION_IN_HOURS: ${TOKEN_EXPIRATION_IN_HOURS}
53+
REFRESH_TOKEN_EXPIRATION_IN_DAYS: ${REFRESH_TOKEN_EXPIRATION_IN_DAYS}
54+
MINUTES_TO_EXPIRE_RECOVERY_CODE: ${MINUTES_TO_EXPIRE_RECOVERY_CODE}
55+
MAX_REQUESTS_PER_MINUTE: ${MAX_REQUESTS_PER_MINUTE}
56+
57+
# smtp
58+
SMTP_HOST: ${SMTP_HOST}
59+
SMTP_PORT: ${SMTP_PORT}
60+
SMTP_USERNAME: ${SMTP_USERNAME}
61+
SMTP_PASSWORD: ${SMTP_PASSWORD}
62+
63+
# swagger
64+
SWAGGER_URL: ${SWAGGER_URL}
4365
volumes:
4466
- ../api:/app
4567
- ./.volumes/maven:/root/.m2
4668
working_dir: /app
4769
networks:
48-
- simple-network
70+
- example-network
4971
tty: true
50-
entrypoint: "mvn spring-boot:run"
72+
entrypoint: [
73+
'mvn',
74+
'spring-boot:run',
75+
'-Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,address=*:${API_DEBUG_PORT},suspend=n"'
76+
]
5177

5278
web:
5379
build:
@@ -57,15 +83,15 @@ services:
5783
restart: unless-stopped
5884
container_name: crud-web
5985
ports:
60-
- "3000:3000"
86+
- "${APP_PORT}:${APP_PORT}"
6187
volumes:
6288
- ../web:/app
6389
working_dir: /app
6490
networks:
65-
- simple-network
91+
- example-network
6692
tty: true
6793
entrypoint: "npm run dev"
6894

6995
networks:
70-
simple-network:
96+
example-network:
7197
driver: bridge

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ This project was started with [Spring Initializr](https://start.spring.io/#!type
6767
```shell
6868
mvn -f api/pom.xml install -DskipTests
6969
```
70-
- run the application
70+
- run the application
71+
- home http://localhost:8080
72+
- api http://localhost:8080/api
73+
- swagger http://localhost:8080/docs
7174
```shell
7275
mvn -f api/pom.xml spring-boot:run
7376
```
@@ -97,10 +100,10 @@ use the parameter `-Dtest=<class>#<method>`
97100

98101

99102
## Swagger
100-
Once the application is up, it is available at: [localhost:8080/documentation](localhost:8080/documentation)
103+
Once the application is up, it is available at: [localhost:8080/docs](http://localhost:8080/docs)
104+
> 🚨 if you set `SWAGGER_USERNAME` and `SWAGGER_PASSWORD` on `.env` file this route require authentication
101105
102-
103-
[example on heroku](https://throyer-crud-api.herokuapp.com/documentation)
106+
[example on heroku](https://throyer-crud-api.herokuapp.com/docs)
104107

105108
---
106109

@@ -164,9 +167,11 @@ Creating database migration files
164167
| **Description** | **Parameter** | **Default values** |
165168
|------------------------------------------|------------------------------------|---------------------------|
166169
| server port | `SERVER_PORT` | 8080 |
167-
| database url | `DB_URL` | localhost:5432/common_app |
168-
| username (database) | `DB_USERNAME` | root |
169-
| user password (database) | `DB_PASSWORD` | root |
170+
| database host | `DB_HOST` | localhost |
171+
| database port | `DB_PORT` | 5432 |
172+
| database name | `DB_NAME` | example |
173+
| database username | `DB_USERNAME` | root |
174+
| database user password | `DB_PASSWORD` | root |
170175
| displays the generated sql in the logger | `DB_SHOW_SQL` | false |
171176
| set maximum database connections | `DB_MAX_CONNECTIONS` | 5 |
172177
| secret value in token generation | `TOKEN_SECRET` | secret |
@@ -177,7 +182,8 @@ Creating database migration files
177182
| SMTP username | `SMTP_USERNAME` | user |
178183
| SMTP server password | `SMTP_PASSWORD` | secret |
179184
| time for recovery email to expire | `MINUTES_TO_EXPIRE_RECOVERY_CODE` | 20 |
180-
| max requests per minute | `MAX_REQUESTS_PER_MINUTE` | 10 |
185+
| max requests per minute | `MAX_REQUESTS_PER_MINUTE` | 50 |
186+
| swagger url | `SWAGGER_URL` | /docs |
181187
| swagger username | `SWAGGER_USERNAME` | `null` |
182188
| swagger password | `SWAGGER_PASSWORD` | `null` |
183189

api/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@
204204
<plugin>
205205
<groupId>org.springframework.boot</groupId>
206206
<artifactId>spring-boot-maven-plugin</artifactId>
207-
<configuration>
208-
<jvmArguments>
209-
-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n
210-
</jvmArguments>
211-
</configuration>
212207
</plugin>
213208
<plugin>
214209
<groupId>org.jacoco</groupId>

api/src/main/resources/application.properties

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ spring.jpa.show-sql=${DB_SHOW_SQL:true}
1212

1313
# Banco de dados
1414
spring.datasource.hikari.maximum-pool-size=${DB_MAX_CONNECTIONS:5}
15-
spring.datasource.url=jdbc:postgresql://${DB_URL:localhost:5432/common_app}
15+
spring.datasource.url=jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:example}
1616
spring.datasource.username=${DB_USERNAME:root}
1717
spring.datasource.password=${DB_PASSWORD:root}
1818
spring.jpa.hibernate.ddl-auto=none
@@ -23,6 +23,9 @@ spring.h2.console.enabled=false
2323
spring.jpa.open-in-view=false
2424

2525
# swagger
26+
springdoc.swagger-ui.path=${SWAGGER_URL:/docs}
27+
swagger.username=${SWAGGER_USERNAME:#{null}}
28+
swagger.password=${SWAGGER_PASSWORD:#{null}}
2629
springdoc.default-produces-media-type=application/json
2730
springdoc.default-consumes-media-type=application/json
2831

@@ -32,13 +35,11 @@ token.refresh.expiration-in-days=${REFRESH_TOKEN_EXPIRATION_IN_DAYS:7}
3235
token.secret=${TOKEN_SECRET:secret}
3336
server.servlet.session.cookie.name=API_EXAMPLE_SESSION_ID
3437
server.servlet.session.cookie.path=/app
35-
swagger.username=${SWAGGER_USERNAME:#{null}}
36-
swagger.password=${SWAGGER_PASSWORD:#{null}}
3738

3839
# smtp configurations
3940
spring.mail.host=${SMTP_HOST:smtp.gmail.com}
4041
spring.mail.port=${SMTP_PORT:587}
41-
spring.mail.username=${SMTP_USERNAME:user}
42+
spring.mail.username=${SMTP_USERNAME:user@gmail}
4243
spring.mail.password=${SMTP_PASSWORD:secret}
4344

4445
spring.mail.properties.mail.smtp.auth=true
@@ -75,7 +76,7 @@ bucket4j.filters[0].metrics.tags[0].expression=getRemoteAddr()
7576
bucket4j.filters[0].strategy=first
7677
bucket4j.filters[0].rate-limits[0].skip-condition=getRequestURI().contains('/swagger-ui') || getRequestURI().contains('/documentation')
7778
bucket4j.filters[0].rate-limits[0].expression=getRemoteAddr()
78-
bucket4j.filters[0].rate-limits[0].bandwidths[0].capacity=${MAX_REQUESTS_PER_MINUTE:10}
79+
bucket4j.filters[0].rate-limits[0].bandwidths[0].capacity=${MAX_REQUESTS_PER_MINUTE:50}
7980
bucket4j.filters[0].rate-limits[0].bandwidths[0].time=1
8081
bucket4j.filters[0].rate-limits[0].bandwidths[0].unit=minutes
8182
bucket4j.filters[0].rate-limits[0].bandwidths[0].fixed-refill-interval=0

0 commit comments

Comments
 (0)