Skip to content

Commit cbba67f

Browse files
committed
Add nginx container
1 parent 30ef5f9 commit cbba67f

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,14 @@ services:
3333
REDIS_PORT: "6379"
3434
RABBITMQ_HOST: rabbitmq
3535
RABBITMQ_PORT: "5672"
36+
37+
nginx:
38+
depends_on:
39+
- pollservice
40+
build:
41+
context: .
42+
dockerfile: docker/nginx.dockerfile
43+
ports:
44+
- "8081:80"
45+
container_name: polling-nginx
3646

docker/nginx.dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM nginx:alpine
2+
3+
WORKDIR /app
4+
5+
COPY src/frontend/my-app/dist /var/www/polling/
6+
7+
COPY nginx/config.conf /etc/nginx/conf.d/default.conf
8+
9+
EXPOSE 80
10+
11+

documentation/component-architecture.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
node "External\nClients" as mu
44
node "PollService" {
5-
node "Nginx" as nginx
5+
component "Nginx" as nginx
66
component "Web UI\n(React)" as ui
77
interface HTTP
88
component "REST API\n(Spring Web MVC)" as api

nginx/config.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
server {
2+
listen 80;
3+
server_name frontend;
4+
location = /polling {return 302 /polling/;
5+
}
6+
7+
8+
location ^~ /polling/ {
9+
root /var/www;
10+
index index.html;
11+
try_files $uri $uri/ /polling/index.html;
12+
}
13+
14+
location ^~ /polling/backend/ {
15+
proxy_pass http://pollservice:8080;
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-Proto $scheme;
19+
proxy_set_header X-Forwarded-Host $host;
20+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21+
}
22+
23+
}
24+
25+

src/main/java/com/example/backend/Security/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
8989
@Bean
9090
CorsConfigurationSource corsConfigurationSource() {
9191
var cfg = new CorsConfiguration();
92-
cfg.setAllowedOrigins(List.of("http://localhost:5173", "https://magnus-demo-project.com"));
92+
cfg.setAllowedOrigins(List.of("http://localhost:5173", "https://magnus-demo-project.com","http://localhost","http://localhost:8081" ));
9393
cfg.setAllowedMethods(List.of("GET","POST","PUT","PATCH","DELETE","OPTIONS"));
9494
cfg.setAllowedHeaders(List.of("Content-Type","X-XSRF-TOKEN","Authorization","X-Requested-With"));
9595
cfg.setAllowCredentials(true);

0 commit comments

Comments
 (0)