From 69f57767bb48d2bd1e55045d4d68015004d04bc8 Mon Sep 17 00:00:00 2001 From: Sosokker Date: Sun, 2 Feb 2025 07:45:01 +0700 Subject: [PATCH] feat: add nginx to serve report --- cmd/Dockerfile | 15 +++ docker-compose.yml | 24 +++++ nginx/Dockerfile | 14 +++ nginx/nginx.conf | 34 +++++++ nginx/web/index.css | 57 ++++++++++++ nginx/web/index.html | 213 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 357 insertions(+) create mode 100644 cmd/Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/Dockerfile create mode 100644 nginx/nginx.conf create mode 100644 nginx/web/index.css create mode 100644 nginx/web/index.html diff --git a/cmd/Dockerfile b/cmd/Dockerfile new file mode 100644 index 0000000..e5cc265 --- /dev/null +++ b/cmd/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.23.5-alpine + +WORKDIR /usr/share/openweather-dashboard + +COPY go.mod . + +COPY go.sum . + +RUN go mod download + +COPY ../. . + +RUN go build -o main . + +CMD ["./main"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c787715 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +services: + backend: + container_name: backend + build: ./cmd + networks: + - internal-net + environment: + - OPENWEATHERMAP_API_KEY=34fec0bf50b5e8cc6c2070005ea3d5b0 + + nginx: + build: + context: nginx + container_name: nginx + volumes: + - ./nginx:/etc/nginx/conf.d/ + networks: + - internal-net + ports: + - "8080:80" + depends_on: + - backend + +networks: + internal-net: \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..6b40153 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,14 @@ +FROM nginx:alpine + +WORKDIR /etc/nginx + +COPY ./nginx.conf ./conf.d/default.conf + +COPY ./web/index.html ./html/report/index.html +COPY ./web/index.css ./html/report/index.css + +EXPOSE 80 + +ENTRYPOINT [ "nginx" ] + +CMD [ "-g", "daemon off;" ] \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..90693c3 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,34 @@ +upstream api { + server backend:8080; +} + +server { + listen 80; + server_name localhost; + + location / { + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent, + X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; + add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; + add_header 'Content-Type' 'application/json'; + add_header 'Content-Length' 0; + return 204; + } + + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent, + X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; + add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; + + proxy_pass http://backend:8080; + } + + location /report { + root html; + index index.html; + } +} \ No newline at end of file diff --git a/nginx/web/index.css b/nginx/web/index.css new file mode 100644 index 0000000..c795b25 --- /dev/null +++ b/nginx/web/index.css @@ -0,0 +1,57 @@ +#main-section { + display: flex; + flex-direction: row; + margin: 2.5rem +} + +#statistic { + flex: 1; + min-width: 300px; + background: #ffffff; + border-radius: 8px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + padding: 1.5rem; + text-align: center; +} + +#table-section { + overflow-x: auto; +} + +#map { + display: flex; + flex-direction: column; + gap: 2rem; + flex: 2; + min-width: 600px; +} + + +// from https://codepen.io/zass-udd/pen/NWqKmdE +table { + border-collapse: collapse; + width: 100%; +} + +td, th { + border: 1px solid #dddddd; + text-align: center; + padding:6px 20px; +} +tr th { + border: 1px solid #dddddd; + text-align: center; + padding:6px 20px; + background-color: #ad1e23; + color:#fff; +} + +tr:hover { + background-color: #dddddd; + cursor: pointer; +} + +.content td, .content th { + border-top: 1px solid transparent; + padding: 2px 10px 2px 15px; +} \ No newline at end of file diff --git a/nginx/web/index.html b/nginx/web/index.html new file mode 100644 index 0000000..b65a9d4 --- /dev/null +++ b/nginx/web/index.html @@ -0,0 +1,213 @@ + + + + + + + Graph + + + + + + + + + + +
+
+

Rainfall Statistics

+

Today rain/hr.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LocationCoordinateRain Per Hour
LatitudeLongitude
80.395±850.27
100.617±678.54
120.888±6113.10
161.580±5201.06
202.470±5314.16
222.984±4380.13
253.850±4490.88
284.840±4615.75
326.310±4804.25
+
+
+
+ +
+ +
+
+ +
+
+
+ + + \ No newline at end of file