From ac152e00aacafd3d9bc889450448d2f2a7ddd0a4 Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Fri, 25 Aug 2023 12:33:23 +0700 Subject: [PATCH 1/8] add netlify configuration --- frontend/public/_redirects | 1 + 1 file changed, 1 insertion(+) create mode 100644 frontend/public/_redirects diff --git a/frontend/public/_redirects b/frontend/public/_redirects new file mode 100644 index 0000000..f824337 --- /dev/null +++ b/frontend/public/_redirects @@ -0,0 +1 @@ +/* /index.html 200 \ No newline at end of file From dabc136c594359a989756a6c1af09b100f6bc9aa Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Wed, 30 Aug 2023 18:38:30 +0700 Subject: [PATCH 2/8] Dockerize frontend with nginx --- frontend/Dockerfile | 33 ++++++++++++++++++++++++++++ nginx/cert/eews.crt | 30 ++++++++++++++++++++++++++ nginx/cert/eews.key | 51 ++++++++++++++++++++++++++++++++++++++++++++ nginx/webserver.conf | 48 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 frontend/Dockerfile create mode 100644 nginx/cert/eews.crt create mode 100644 nginx/cert/eews.key create mode 100644 nginx/webserver.conf diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..e69ab35 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,33 @@ +# stage1 as builder +FROM node:14 as builder + +# copy the package.json to install dependencies +COPY /frontend/package.json /frontend/package-lock.json ./ + +# Install the dependencies and make the folder +RUN npm install && mkdir /frontend && mv ./node_modules ./frontend + +WORKDIR /frontend + +COPY /frontend . + +# Build the project and copy the files +RUN npm run build + + +FROM nginx:alpine + +#!/bin/sh + +COPY /nginx/webserver.conf /etc/nginx/nginx.conf +COPY /nginx/cert/ /etc/nginx/cert + +## Remove default nginx index page +RUN rm -rf /usr/share/nginx/html/* + +# Copy from the stahg 1 +COPY --from=builder /frontend/build /usr/share/nginx/html + +EXPOSE 8000 80 443 + +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/cert/eews.crt b/nginx/cert/eews.crt new file mode 100644 index 0000000..9c8dbd0 --- /dev/null +++ b/nginx/cert/eews.crt @@ -0,0 +1,30 @@ +-----BEGIN CERTIFICATE----- +MIIFMzCCAxsCFEbN0eSoZJRk/3GRCzvBeWD/IH1AMA0GCSqGSIb3DQEBCwUAMFYx +CzAJBgNVBAYTAklEMRAwDgYDVQQIDAdKYWthcnRhMSEwHwYDVQQKDBhJbnRlcm5l +dCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0yMzA4MzAw +MzQ1NDNaFw0yMzA5MjkwMzQ1NDNaMFYxCzAJBgNVBAYTAklEMRAwDgYDVQQIDAdK +YWthcnRhMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV +BAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAME3 +d7V2WuKayQAUYnf3NJIHBsALfaZQHjQX04V+GSPAhfvtg4455T8TYucnmFgtO0yq +1NHDmVZDLvFjkBXIRWFQCKU9zea/4Vh1ptmJefAGcD9ZWTMslGsEGfW0fSTA0Rhj +tuqOm8HWVNL6eul6d+ODTilQREqITd+2eevuGAoiux8gUVR1wSx56GR03cRaKSuW +dSzHOavRDg+PFHNhrMT3OfzGPofRu9y4mUNQ7Il6bmOalCTqfKGQi0sAoB7QRwZN +y88Roe35DxoAvOmXqeXRa0tGJdsZB7+OxzbnGkLRA0cP61vCzEUfYBYihqn7/BxN +c1LwUxLDdjlyyLsqWJRfevDdkmV2mg4ngBA4OKpnmavEXVE16IvdMRLf/I+WRQu1 +7epj6uvRSp+BqxlVNzdnBOt9Z+Wzcr+r1Ru87E+cS2+FzKXdeHlx/2s0rEBtU4W4 +fW6U1u/HciIl7lPpmUUWA4dNpbIp9oORct4V84qzx/gJvfuF4SjvpOnCvXkUn0t+ +p/An3yA8GV/SbhpRwCHGHrCvpjCrPsYAPkTsPZ1MIWTiTmnJ41a4CO17PIKSFcdB +GGj09OCEp5YLvUM55gpK9J4U0pUfJ9SoZcbzSSwXMspzUNL08ic7Ca655xBNoGTh +Rv+T/P6nIolfpqQk37m31McsBg2dnHBcKhvokaILAgMBAAEwDQYJKoZIhvcNAQEL +BQADggIBAKy0osxFzBk5zmWb0MW9Td+kaNB7/b5TuKfjl9OZn2QFsvNI/+A6cw6g +iN/EAukqvLku6NpOmlaDW7/cCXH0IO5yCsRpcTztXYBEICPlk0N3sFAiZcKruFrd +xI5VBNvqydLWsG9OQcwx+3vPnOorw0M4mHmkZDQiJSlJSZ45gevIecqm5soVxiTO +XUnZcNhab+jZjks2s1cDqnQHzROLvHCUScff29GcUdK1jdThv8YQNqsSnzN4IJ+H +V848Ujjid/7hkfqFi6w39X+84NnIitmcjt5OZVkfQ2Xhv02J0FYYk3iulE+ftjMy +kLdRmNyYaEQIJsAaJahotxsnIIIEWYfjTpprFX7qRfxoxF5PWgKwzczym2b1WkgL +kemHOtYySyVBtvQVXRkwnBZq9/V7fwyhU7RN+Nv1L4+cyd14ZEBRRUsllSi6bTiH +gB6F2pGN+cuY1AGCAYotkLwPphPaHZkRIho/blM2byTY9+8cLHcyfMr1mngJYjt8 +PQuuBSxMUxawgnENtide/h16/WdiuN3f24qFsTcBE5fCGA1UsNKj6OOfAz2e/9oZ +fTaLgqv3MUgFlI6r+fc36YOZ4AVEFWNCGAfElSVQRsgeR9otDg4EwDnSARTNPTrm +EgQ8k3y90Z1GjlDYbPzuP9WKhdxSUpImb1fx6aRvxQIJO6QLe2nC +-----END CERTIFICATE----- diff --git a/nginx/cert/eews.key b/nginx/cert/eews.key new file mode 100644 index 0000000..5da2e3b --- /dev/null +++ b/nginx/cert/eews.key @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKgIBAAKCAgEAwTd3tXZa4prJABRid/c0kgcGwAt9plAeNBfThX4ZI8CF++2D +jjnlPxNi5yeYWC07TKrU0c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S4zhd4dG5hIILIdTGQEyn4W1ogV/XP4mc/nG3FCO +8S2/zYX77o+61bZuJCIA+cvt5nfu5QheJSugvP0bKH5npabAjYULeyjKgWsI8HrR +K17hOD1Se8ui4Jw9c+eWZ+EPyjA50BNVWDxLQsyfLoPYTZZlhPlB6m8ECR0hsIKf +TEs3yT6HuZR0GQzS592Is3suVFiMs3sDZImP+P/bre/WCLUatacOOAXGPglZ5gnT +LjDLmQKCAQEAv3tUYJNrBDio1kuJKprZynDBk9/Q7R2YjEw4XqxGbS/qB67KZbz9 +ukwiQONtthC8G+5nZYhq+3fNNAqgyhCNTYR7aG41PgHqGn3dLvnzDtoDHd4EV0jh +JJN1pzKcUuj//d8SlIG+G/1Ssm9BAV8ywNXO7PJ4yoxwi7ANHPe+isO7xkp/2e7O +2shuXEujo+Rd2KtaCbvB8EOC7OBxtILKK1EiS7HRcEfdp5hJiSnFTa7ECRxizy+4 +D4y/LF7IebO3oX1BCKISq/9y9thxckgnNrpGKFfCR9MDzbqry3IkgdOaRmR9yo/t +4VBad5Ob8SxqGzfMLfBwGq5JlemokGZq8wKCAQEAtA+tkLnUnbRCH7lc5fpwnBiE +vne33cg4FvD787ZlOnHvdH7FR+PzkoWJLmuvUfdAtEE4X/A/wYvBEesv24xPDeC6 +Y/2jayea93tkd+h0P/rgBr2xCLC3PvfWGHfMa/JgRSOQiRVOU7gIj0TcajX8rGqg +LMABdQ7Gz3gI1dl0IhxeruBmJu0uP3wpj1wu8RQJt2GLuCF+McY52lZl2wrKF7bd +r1XNhmJED2LgGr3oUlYG/vRLkyGCTvt94osDkP4wxuABAU/cqcJRNP+DySId7c7m +Mqtyks4Z4CxGoZJSXsCbtbibQwDSxCHY544fLS9lCPghHfXjrtXYnGVCmXi0Og== +-----END RSA PRIVATE KEY----- diff --git a/nginx/webserver.conf b/nginx/webserver.conf new file mode 100644 index 0000000..7b7f654 --- /dev/null +++ b/nginx/webserver.conf @@ -0,0 +1,48 @@ +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + upstream backend { + server 127.0.1.1; + # server host.docker.internal:8001; # windows + # server host.docker.internal:8002; + } + + server { + listen 80; + listen 443 ssl; + + root /usr/share/nginx/html; + include /etc/nginx/mime.types; + + ssl_certificate /etc/nginx/cert/eews.crt; + ssl_certificate_key /etc/nginx/cert/eews.key; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; + ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; + ssl_prefer_server_ciphers on; + + location / { + try_files $uri $uri/ /index.html; + } + } + + server { + listen 8000; + + location / { + proxy_pass http://backend; + } + } + + server { + listen 127.0.1.1; + + location / { + proxy_pass http://34.87.72.104:80; + } + } +} From 019f0565b75e8e3d43542f4569c8e2abcb21ddcb Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Thu, 31 Aug 2023 17:53:41 +0700 Subject: [PATCH 3/8] Change production configuration --- .gitignore | 1 + frontend/Dockerfile | 6 +++++- frontend/src/App.js | 5 +++-- nginx/cert/eews.crt | 30 -------------------------- nginx/cert/eews.key | 51 -------------------------------------------- nginx/webserver.conf | 9 +++----- 6 files changed, 12 insertions(+), 90 deletions(-) delete mode 100644 nginx/cert/eews.crt delete mode 100644 nginx/cert/eews.key diff --git a/.gitignore b/.gitignore index 8560c64..0d91c34 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ db.sqlite3 # production /build +/nginx/cert # misc .DS_Store diff --git a/frontend/Dockerfile b/frontend/Dockerfile index e69ab35..60f627e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -11,6 +11,10 @@ WORKDIR /frontend COPY /frontend . +ARG REACT_APP_API + +ENV REACT_APP_API 34.87.114.141 + # Build the project and copy the files RUN npm run build @@ -28,6 +32,6 @@ RUN rm -rf /usr/share/nginx/html/* # Copy from the stahg 1 COPY --from=builder /frontend/build /usr/share/nginx/html -EXPOSE 8000 80 443 +EXPOSE 80 443 ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/src/App.js b/frontend/src/App.js index f14fe05..c55dcfb 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -10,15 +10,16 @@ import About from "./pages/About"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; const App = () => { + var api = process.env.NODE_ENV == 'production'? process.env.REACT_APP_API + '/api': 'localhost:8000'; return ( - } /> + } /> } /> } + element={} /> } /> } /> diff --git a/nginx/cert/eews.crt b/nginx/cert/eews.crt deleted file mode 100644 index 9c8dbd0..0000000 --- a/nginx/cert/eews.crt +++ /dev/null @@ -1,30 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFMzCCAxsCFEbN0eSoZJRk/3GRCzvBeWD/IH1AMA0GCSqGSIb3DQEBCwUAMFYx -CzAJBgNVBAYTAklEMRAwDgYDVQQIDAdKYWthcnRhMSEwHwYDVQQKDBhJbnRlcm5l -dCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0yMzA4MzAw -MzQ1NDNaFw0yMzA5MjkwMzQ1NDNaMFYxCzAJBgNVBAYTAklEMRAwDgYDVQQIDAdK -YWthcnRhMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV -BAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAME3 -d7V2WuKayQAUYnf3NJIHBsALfaZQHjQX04V+GSPAhfvtg4455T8TYucnmFgtO0yq -1NHDmVZDLvFjkBXIRWFQCKU9zea/4Vh1ptmJefAGcD9ZWTMslGsEGfW0fSTA0Rhj -tuqOm8HWVNL6eul6d+ODTilQREqITd+2eevuGAoiux8gUVR1wSx56GR03cRaKSuW -dSzHOavRDg+PFHNhrMT3OfzGPofRu9y4mUNQ7Il6bmOalCTqfKGQi0sAoB7QRwZN -y88Roe35DxoAvOmXqeXRa0tGJdsZB7+OxzbnGkLRA0cP61vCzEUfYBY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b1fx6aRvxQIJO6QLe2nC ------END CERTIFICATE----- diff --git a/nginx/cert/eews.key b/nginx/cert/eews.key deleted file mode 100644 index 5da2e3b..0000000 --- a/nginx/cert/eews.key +++ /dev/null @@ -1,51 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIJKgIBAAKCAgEAwTd3tXZa4prJABRid/c0kgcGwAt9plAeNBfThX4ZI8CF++2D -jjnlPxNi5yeYWC07TKrU0cOZVkMu8WOQFchFYVAIpT3N5r/hWHWm2Yl58AZwP1lZ -MyyUawQZ9bR9JMDRGGO26o6bwdZU0vp66Xp344NOKVBESohN37Z56+4YCiK7HyBR -VHXBLHnoZHTdxFopK5Z1LMc5q9EOD48Uc2GsxPc5/MY+h9G73LiZQ1DsiXpuY5qU -JOp8oZCLSwCgHtBHBk3LzxGh7fkPGgC86Zep5dFrS0Yl2xkHv47HNucaQtEDRw/r -W8LMRR9gFiKGqfv8HE1zUvBTEsN2OXLIuypYlF968N2SZXaaDieAEDg4qmeZq8Rd -UTXoi90xEt/8j5ZFC7Xt6mPq69FKn4GrGVU3N2cE631n5bNyv6vVG7zsT5xLb4XM -pd14eXH/azSsQG1Thbh9bpTW78dyIiXuU+mZRRYDh02lsin2g5Fy3hXzirPH+Am9 -+4XhKO+k6cK9eRSfS36n8CffIDwZX9JuGlHAIcYesK+mMKs+xgA+ROw9nUwhZOJO -acnjVrgI7Xs8gpIVx0EYaPT04ISnlgu9QznmCkr0nhTSlR8n1KhlxvNJLBcyynNQ -0vTyJzsJrrnnEE2gZOFG/5P8/qciiV+mpCTfubfUxywGDZ2ccFwqG+iRogsCAwEA -AQKCAgBfwr7ox9T5lF9kU7YN4Q5EBYl56vgGUpT1mo1yDvIkvwlot+nItrcA0Pnm -uMAPi7NlJxG9OOUpVLjSWFcUBKMmPMVcKEqBP75O2lisXi96H6bILt8/tquEco7v -MNoJOisnnFwO2kkmA7Ucr5n1V4ZN00kMvsRp8C4wXz8ECIgPlfEJ1zmX05i/E1hz -WVyEM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3oUlYG/vRLkyGCTvt94osDkP4wxuABAU/cqcJRNP+DySId7c7m -Mqtyks4Z4CxGoZJSXsCbtbibQwDSxCHY544fLS9lCPghHfXjrtXYnGVCmXi0Og== ------END RSA PRIVATE KEY----- diff --git a/nginx/webserver.conf b/nginx/webserver.conf index 7b7f654..e664042 100644 --- a/nginx/webserver.conf +++ b/nginx/webserver.conf @@ -6,6 +6,7 @@ events { http { upstream backend { + ip_hash; server 127.0.1.1; # server host.docker.internal:8001; # windows # server host.docker.internal:8002; @@ -28,13 +29,9 @@ http { location / { try_files $uri $uri/ /index.html; } - } - - server { - listen 8000; - location / { - proxy_pass http://backend; + location ~ ^/api(/.*)$ { + proxy_pass http://backend$1; } } From 7bdb349305b1986888cb745dca962f4ce3e3a2e6 Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Sun, 8 Oct 2023 19:53:25 +0700 Subject: [PATCH 4/8] update nginx config --- nginx/webserver.conf | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nginx/webserver.conf b/nginx/webserver.conf index e664042..abeeb02 100644 --- a/nginx/webserver.conf +++ b/nginx/webserver.conf @@ -8,8 +8,7 @@ http { upstream backend { ip_hash; server 127.0.1.1; - # server host.docker.internal:8001; # windows - # server host.docker.internal:8002; + server 127.0.1.2; } server { @@ -39,7 +38,15 @@ http { listen 127.0.1.1; location / { - proxy_pass http://34.87.72.104:80; + proxy_pass http://34.101.239.0:80; + } + } + + server { + listen 127.0.1.2; + + location / { + proxy_pass http://34.101.45.253:80; } } } From 52818f261a241dec7a314e6c1b603e93f87a221a Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Mon, 16 Oct 2023 12:48:21 +0700 Subject: [PATCH 5/8] deployment adjustment --- eews_backend/database/mongodb.py | 4 +++- eews_backend/rest/Dockerfile | 2 +- eews_backend/rest/main.py | 11 +++++---- frontend/Dockerfile | 4 ++-- frontend/public/index.html | 4 ++-- frontend/public/manifest.json | 10 -------- frontend/src/App.js | 2 +- frontend/src/components/Map/Map2.js | 4 ++-- nginx/webserver.conf | 36 +++++++++++++++++++++++++++++ 9 files changed, 54 insertions(+), 23 deletions(-) diff --git a/eews_backend/database/mongodb.py b/eews_backend/database/mongodb.py index 3711b3d..30a40c5 100644 --- a/eews_backend/database/mongodb.py +++ b/eews_backend/database/mongodb.py @@ -17,6 +17,8 @@ def mongo_client(): mongo_url = MONGO_URL mongo_db = MONGO_DATABASE - client = motor_asyncio.AsyncIOMotorClient(mongo_url) + MONGO_USERNAME = os.getenv("MONGO_USERNAME") + MONGO_PASSWORD = os.getenv("MONGO_PASSWORD") + client = motor_asyncio.AsyncIOMotorClient(mongo_url, username=MONGO_USERNAME, password=MONGO_PASSWORD) db = client[mongo_db] return client, db diff --git a/eews_backend/rest/Dockerfile b/eews_backend/rest/Dockerfile index 6d909bb..3044803 100644 --- a/eews_backend/rest/Dockerfile +++ b/eews_backend/rest/Dockerfile @@ -4,7 +4,7 @@ ENV APP_HOME /app WORKDIR $APP_HOME COPY . ./ -ENV PORT 8000 +ENV PORT 80 EXPOSE $PORT RUN pip install --no-cache-dir -r requirements.txt diff --git a/eews_backend/rest/main.py b/eews_backend/rest/main.py index 2b735b6..db750e0 100644 --- a/eews_backend/rest/main.py +++ b/eews_backend/rest/main.py @@ -49,10 +49,13 @@ STATIC_DIR = "static/" SIMULATE_REALTIME = False if os.getenv("SIMULATE_REALTIME") == "False" else True MSEED_RANGE_IN_SECONDS = 30 +BACKEND_IP = os.getenv("BACKEND_IP") if os.getenv("BACKEND_IP") else "localhost" origins = [ + "http://host.docker.internal", "http://localhost", "http://localhost:3000", + f"http://{BACKEND_IP}" ] app = FastAPI() @@ -75,7 +78,7 @@ _, db = mongo_client() client = influx_client() -HTML = """ +HTML = f""" @@ -90,7 +93,7 @@
--> diff --git a/frontend/public/manifest.json b/frontend/public/manifest.json index 080d6c7..1f2f141 100644 --- a/frontend/public/manifest.json +++ b/frontend/public/manifest.json @@ -6,16 +6,6 @@ "src": "favicon.ico", "sizes": "64x64 32x32 24x24 16x16", "type": "image/x-icon" - }, - { - "src": "logo192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "logo512.png", - "type": "image/png", - "sizes": "512x512" } ], "start_url": ".", diff --git a/frontend/src/App.js b/frontend/src/App.js index c55dcfb..ed4ad7a 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -10,7 +10,7 @@ import About from "./pages/About"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; const App = () => { - var api = process.env.NODE_ENV == 'production'? process.env.REACT_APP_API + '/api': 'localhost:8000'; + var api = process.env.NODE_ENV == 'production'? process.env.REACT_APP_API : 'localhost'; return ( diff --git a/frontend/src/components/Map/Map2.js b/frontend/src/components/Map/Map2.js index b621243..fa15626 100644 --- a/frontend/src/components/Map/Map2.js +++ b/frontend/src/components/Map/Map2.js @@ -46,8 +46,8 @@ const Map = (props) => { jsonData.forEach((element) => { L.marker( [ - element["location"]["coordinates"][0], - element["location"]["coordinates"][1], + element["location"]["coordinates"][1], // latitude + element["location"]["coordinates"][0], // longitude ], { icon: customMarkerIcon(element["name"]) } ) diff --git a/nginx/webserver.conf b/nginx/webserver.conf index abeeb02..b6f24fd 100644 --- a/nginx/webserver.conf +++ b/nginx/webserver.conf @@ -1,10 +1,25 @@ worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + events { worker_connections 1024; } http { + log_format custom '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" "$gzip_ratio"' + ' Proxy: "$proxy_host" "$upstream_addr"'; + + access_log /var/log/nginx/access.log custom; + + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + upstream backend { ip_hash; server 127.0.1.1; @@ -32,6 +47,27 @@ http { location ~ ^/api(/.*)$ { proxy_pass http://backend$1; } + + location ~ .*(\/ws)$ { + proxy_pass http://backend$1; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + proxy_set_header Origin "http://localhost"; + proxy_hide_header Access-Control-Allow-Origin; + add_header Access-Control-Allow-Origin $http_origin; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + + proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions; + proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key; + proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version; + } } server { From 8c681adf610297c2f48b851411102a6acc00d98e Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Thu, 9 Nov 2023 10:02:00 +0700 Subject: [PATCH 6/8] adjust environment variable --- eews_backend/rest/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/eews_backend/rest/main.py b/eews_backend/rest/main.py index db750e0..41d2b55 100644 --- a/eews_backend/rest/main.py +++ b/eews_backend/rest/main.py @@ -48,7 +48,8 @@ MODULE_DIR = "./rest/" STATIC_DIR = "static/" SIMULATE_REALTIME = False if os.getenv("SIMULATE_REALTIME") == "False" else True -MSEED_RANGE_IN_SECONDS = 30 +SIMULATE_DATETIME = os.getenv("SIMULATE_DATETIME") +MSEED_RANGE_IN_SECONDS = os.getenv("MSEED_RANGE_IN_SECONDS") BACKEND_IP = os.getenv("BACKEND_IP") if os.getenv("BACKEND_IP") else "localhost" origins = [ @@ -229,10 +230,10 @@ async def websocket_endpoint(websocket: WebSocket): await manager.connect(websocket) try: query_api = client.query_api() - now = datetime(2023, 10, 9, 2, 18, 19, tzinfo=timezone.utc) # Date for simulation purposes + now = parser.parse(SIMULATE_DATETIME) # Date for simulation purposes if SIMULATE_REALTIME: now = datetime.now(tz=timezone.utc) - timedelta( - seconds=MSEED_RANGE_IN_SECONDS + seconds = MSEED_RANGE_IN_SECONDS ) while True: start = time.monotonic_ns() From ddfaaf1b07e14c41692fae14268cc377595c2535 Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Sat, 11 Nov 2023 13:28:17 +0700 Subject: [PATCH 7/8] adjust environment variable --- eews_backend/rest/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eews_backend/rest/main.py b/eews_backend/rest/main.py index 41d2b55..627af9f 100644 --- a/eews_backend/rest/main.py +++ b/eews_backend/rest/main.py @@ -51,12 +51,14 @@ SIMULATE_DATETIME = os.getenv("SIMULATE_DATETIME") MSEED_RANGE_IN_SECONDS = os.getenv("MSEED_RANGE_IN_SECONDS") BACKEND_IP = os.getenv("BACKEND_IP") if os.getenv("BACKEND_IP") else "localhost" +FRONTEND_IP = os.getenv("FRONTEND_IP") if os.getenv("FRONTEND_IP") else "localhost" origins = [ "http://host.docker.internal", "http://localhost", "http://localhost:3000", - f"http://{BACKEND_IP}" + f"http://{BACKEND_IP}", + f"http://{FRONTEND_IP}" ] app = FastAPI() @@ -233,7 +235,7 @@ async def websocket_endpoint(websocket: WebSocket): now = parser.parse(SIMULATE_DATETIME) # Date for simulation purposes if SIMULATE_REALTIME: now = datetime.now(tz=timezone.utc) - timedelta( - seconds = MSEED_RANGE_IN_SECONDS + seconds = int(MSEED_RANGE_IN_SECONDS) ) while True: start = time.monotonic_ns() From 8b53dce7fa4afde1e17ac58b8b5e7b521cc0b11a Mon Sep 17 00:00:00 2001 From: Natasya Zahra Date: Wed, 15 Nov 2023 14:13:58 +0700 Subject: [PATCH 8/8] adjust environment variable --- eews_backend/rest/main.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/eews_backend/rest/main.py b/eews_backend/rest/main.py index 627af9f..0ba78fb 100644 --- a/eews_backend/rest/main.py +++ b/eews_backend/rest/main.py @@ -49,7 +49,8 @@ STATIC_DIR = "static/" SIMULATE_REALTIME = False if os.getenv("SIMULATE_REALTIME") == "False" else True SIMULATE_DATETIME = os.getenv("SIMULATE_DATETIME") -MSEED_RANGE_IN_SECONDS = os.getenv("MSEED_RANGE_IN_SECONDS") +LENGTH_DATA_IN_SECONDS = int(os.getenv("LENGTH_DATA_IN_SECONDS")) +MSEED_RANGE_IN_SECONDS = int(os.getenv("MSEED_RANGE_IN_SECONDS")) BACKEND_IP = os.getenv("BACKEND_IP") if os.getenv("BACKEND_IP") else "localhost" FRONTEND_IP = os.getenv("FRONTEND_IP") if os.getenv("FRONTEND_IP") else "localhost" @@ -169,10 +170,10 @@ async def post(): @app.get("/test") async def test(): query_api = client.query_api() - now = datetime(2015, 8, 20, 15, 11, 47, tzinfo=timezone.utc) + now = parser.parse(SIMULATE_DATETIME) # Date for simulation purposes query = f""" from(bucket: "eews") - |> range(start: {(now - timedelta(seconds=1)).isoformat()}, stop: {now.isoformat()}) + |> range(start: {(now - timedelta(seconds=LENGTH_DATA_IN_SECONDS)).isoformat()}, stop: {now.isoformat()}) |> filter(fn: (r) => r["_measurement"] == "p_arrival" or r["_measurement"] == "seismograf")""" data: TableList = query_api.query(query=query) result = {} @@ -207,7 +208,7 @@ async def test(): await db["prediction"] .find( { - "p-arrival": {"$lte": now - timedelta(seconds=1)}, + "p-arrival": {"$lte": now - timedelta(seconds=LENGTH_DATA_IN_SECONDS)}, "expired": {"$gte": now}, } ) @@ -216,7 +217,7 @@ async def test(): for p in prediction: del p["_id"] - print(now - timedelta(seconds=1)) + print(now - timedelta(seconds=LENGTH_DATA_IN_SECONDS)) print(now) return {"data": result, "prediction": prediction} # return extended_data.to_dict() @@ -235,13 +236,14 @@ async def websocket_endpoint(websocket: WebSocket): now = parser.parse(SIMULATE_DATETIME) # Date for simulation purposes if SIMULATE_REALTIME: now = datetime.now(tz=timezone.utc) - timedelta( - seconds = int(MSEED_RANGE_IN_SECONDS) + seconds = MSEED_RANGE_IN_SECONDS # Realtime delay from seedlink ) while True: start = time.monotonic_ns() + # Query LENGTH_DATA_IN_SECONDS worth of data query = f""" from(bucket: "eews") - |> range(start: {(now - timedelta(seconds=1)).strftime("%Y-%m-%dT%H:%M:%S.%fZ")}, stop: {now.strftime("%Y-%m-%dT%H:%M:%S.%fZ")}) + |> range(start: {(now - timedelta(seconds=LENGTH_DATA_IN_SECONDS)).strftime("%Y-%m-%dT%H:%M:%S.%fZ")}, stop: {now.strftime("%Y-%m-%dT%H:%M:%S.%fZ")}) |> filter(fn: (r) => r["_measurement"] == "p_arrival" or r["_measurement"] == "seismograf")""" data: TableList = query_api.query(query=query) result = {} @@ -276,7 +278,7 @@ async def websocket_endpoint(websocket: WebSocket): await db["prediction"] .find( { - "p-arrival": {"$lte": now - timedelta(seconds=1)}, + "p-arrival": {"$lte": now - timedelta(seconds=LENGTH_DATA_IN_SECONDS)}, "expired": {"$gte": now}, } ) @@ -288,10 +290,10 @@ async def websocket_endpoint(websocket: WebSocket): del p["expired"] json_data = json.dumps({"data": result, "prediction": prediction}) - now += timedelta(seconds=1) + now += timedelta(seconds=LENGTH_DATA_IN_SECONDS) await manager.broadcast(json_data) diff = (time.monotonic_ns() - start) / 10**9 - await asyncio.sleep(1 - diff) + await asyncio.sleep(LENGTH_DATA_IN_SECONDS - diff) except Exception as e: log.error(e) log.warning(f"Client {websocket} has been disconnected")