Skip to content

Commit

Permalink
feature: add port binding for backend and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise committed Sep 7, 2023
1 parent 5ba0117 commit e95973e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ There are two different images for the service:
* `msdeluise/plant-it-frontend`

This images can be use indipendently, or they can be use in a docker-compose file.
For the sake of simplicity, the provided docker-compose.yml file is reported here:
For the sake of simplicity, the provided `docker-compose.yml` file is reported here:
```
version: "3"
name: plant-it
Expand Down Expand Up @@ -94,13 +94,26 @@ Run the docker compose file (`docker compose -f <file> up -d`), then the service
Please notice that running the `docker-compose` file from another machine change the way to connect to the server. For example, if you run the `docker-compose` on the machine with the local IP `192.168.1.100` then you have to change the backend url in the [API_URL](#configuration) variable to `http://192.168.1.100:8080/api`. In this case, the frontend of the system will be available at `http://192.168.1.100:8080`, and the backend will be available at `http://192.168.1.100:8080/api`.
</details>

#### Change port binding
##### With reverse proxy
The `reverse-proxy` service in the provided docker-compose file is used only to route both backend and frontend request on the same port (`8080` by default).
If you want to continue having this behaviour but change the used port you can modify the port binding in the service declaration as follow: `"<your port>:80"`.

##### Without reverse proxy
If you don't want to use the reverse proxy, you can remove the service from the file and then modify the following [configuration properties](#configuration):
* in the `backend.env` file:
* `API_PORT`: port to serve the backend
* in the `frontend.env` file:
* `PORT`: port to serve the frontend
* `API_URL`: address of the API, e.g. `http//localhost:<API_PORT>/api`

### Setup without docker
The application was developed with being used with Docker in mind, thus this method is not preferred.

#### Requirements
* [JDK 19+](https://openjdk.org/)
* [JDK 20+](https://openjdk.org/)
* [MySQL](https://www.mysql.com/)
* [React](https://reactjs.org/)
* [ReactJS](https://reactjs.org/)

#### Run
1. Be sure to have the `mysql` database up and running
Expand All @@ -121,21 +134,26 @@ There are 2 configuration file available:
MYSQL_PORT=3306
MYSQL_USERNAME=root
MYSQL_PSW=root
JWT_SECRET=putTheSecretHere
JWT_EXP=1
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=bootdb
JWT_SECRET=putTheSecretHere
JWT_EXP=1
USERS_LIMIT=-1 # including the admin account, so <= 0 if undefined, >= 2 if defined
UPLOAD_DIR= # path to the directory used to store uploaded images, if on docker deployment leave as it is and change the volume binding in the docker-compose file if needed
CACHE_TTL=86400
CACHE_HOST=cache
CACHE_PORT=6379
TRAFLE_KEY= # put you key here, otherwise the "search" feature will include only user generated species
UPLOAD_DIR= # path to the directory used to store uploaded images, if on docker deployment leave as it is and change the volume binding if needed
```
Change the properties values according to your system.

* `deployment/frontend.env`: file containing the configuration for the frontend. An example of content is the following:
```
PORT=3000 # port that will serve the frontend, if on docker deployment leave as it is and change the port binding in the docker-compose file if needed
API_URL=http://localhost:8080/api
BROWSER=none
PAGE_SIZE=25
Expand All @@ -149,7 +167,7 @@ Feel free to contribute and help improve the repo.
You can submit any of this in the [issues](https:/MDeLuise/plant-it/issues/new/choose) section of the repository. Chose the right template and then fill the required info.

### Bug fix
If you fix a bug, please follow the [contribution-guideline](https:/MDeLuise/plant-it#how-to-contribute) in order to merge the fix in the repository.
If you fix a bug, please follow the [contribution guideline](https:/MDeLuise/plant-it#how-to-contribute) in order to merge the fix in the repository.

### Feature development
Let's discuss first possible solutions for the development before start working on that, please open a [feature request issue](https:/MDeLuise/plant-it/issues/new?assignees=&labels=&projects=&template=fr.yml).
Expand All @@ -169,6 +187,6 @@ To fix a bug or create a feature, follow these steps:
#### Local environment
If you want to make some changes in the project, you can use the following commands:
* in order to run the frontend: `cd frontend`, then `npm run dev`.
* in order to run the backend: `cd backend`, then `./mvnw spring-boot:run -Dspring-boot.run.profiles=dev`. This enables the `dev` profile, which uses an embedded h2 database instead of one external mysql instance, and creates a user with username `user` and password `user` with a predefined plant's collection.
* in order to run the backend: `cd backend`, then `./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -DcopyFiles`. This enables the `dev` profile, which uses an embedded h2 database instead of one external mysql instance, and creates a user with username `user` and password `user` with a predefined plant's collection. Also a dummy user uploaded image is copied under `/tmp/plant-it/` directory.

Consider that this environment speed up the developing process, but the app should be tested (at least for new big features) even without the `dev` backend profile and with a local docker deployment.
2 changes: 1 addition & 1 deletion backend/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jwt.cookie.name = plant-it
#
# Server config
#
server.port = 8085
server.port = ${API_PORT:8080}
server.servlet.context-path = /api


Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/resources/application-integration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jwt.cookie.name = plant-it
#
# Server config
#
server.port = 8090
server.port = ${API_PORT:8090}
server.address = 0.0.0.0


Expand All @@ -63,9 +63,9 @@ app.version = @project.version@
#
# System config
#
users.max = -1
users.max = ${USERS_LIMIT:-1}
trefle.key =
upload.location = /tmp/plant-it
upload.location = ${UPLOAD_DIR:/tmp/plant-it}


#
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jwt.cookie.name = plant-it
#
# Server config
#
server.port = 8080
server.port = ${API_PORT:8080}
server.servlet.context-path = /api


Expand Down
1 change: 1 addition & 0 deletions deployment/backend.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ USERS_LIMIT=2 # including the admin account, so <= 0 if undefined, >= 2 if defin
CACHE_TTL=86400
CACHE_HOST=cache
CACHE_PORT=6379
API_PORT=8080
1 change: 1 addition & 0 deletions deployment/frontend.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
API_URL=http://localhost:8080/api
PORT=3001
BROWSER=none
PAGE_SIZE=25
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
API_URL=http://localhost:8085/api
PORT=9095
PAGE_SIZE=25

0 comments on commit e95973e

Please sign in to comment.