diff --git a/compose.benefit-backend.yml b/compose.benefit-backend.yml new file mode 100644 index 0000000000..6fe1872d9f --- /dev/null +++ b/compose.benefit-backend.yml @@ -0,0 +1,65 @@ +version: "3.8" +name: yjdh-benefit +services: + postgres: + build: + context: ./backend + dockerfile: ./docker/finnish_postgres.Dockerfile + restart: on-failure + environment: + POSTGRES_USER: benefit + POSTGRES_PASSWORD: benefit + POSTGRES_DB: benefit + LC_COLLATE: "fi_FI.UTF-8" + LC_CTYPE: "fi_FI.UTF-8" + ports: + - 5434:5432 + volumes: + - pgdata:/var/lib/postgresql/data + container_name: benefit-db + + backend: + build: + context: ./backend + dockerfile: ./docker/benefit.Dockerfile + target: development + env_file: + - .env.benefit-backend + environment: + DATABASE_URL: postgres://benefit:benefit@benefit-db/benefit + DATABASE_HOST: benefit-db.helsinki + volumes: + - ./backend/benefit:/app + - ./backend/shared:/shared + depends_on: + - postgres + container_name: benefit-backend + + local-proxy: + depends_on: + - postgres + - backend + build: + context: ./localdevelopment/benefit/nginx + container_name: benefit-local-proxy + volumes: + - ./localdevelopment/benefit/nginx/:/etc/nginx/ + ports: + - 127.0.0.1:8000:8000 + + mailhog: + image: "mailhog/mailhog@sha256:8d76a3d4ffa32a3661311944007a415332c4bb855657f4f6c57996405c009bea" + ports: + - 1025:1025 + - 8025:8025 + container_name: benefit-mailhog + networks: + - default + +volumes: + pgdata: + driver: local + +networks: + default: + name: helsinki diff --git a/frontend/benefit/.gitignore b/frontend/benefit/.gitignore new file mode 100644 index 0000000000..d4baa33405 --- /dev/null +++ b/frontend/benefit/.gitignore @@ -0,0 +1 @@ +certificates/ \ No newline at end of file diff --git a/frontend/shared/src/server/next-server.js b/frontend/shared/src/server/next-server.js index c5975d6f92..73220b4126 100644 --- a/frontend/shared/src/server/next-server.js +++ b/frontend/shared/src/server/next-server.js @@ -1,6 +1,7 @@ const express = require('express'); const next = require('next'); - +const https = require('https'); +const fs = require('fs'); const port = process.env.PORT || 3000; const app = next({ dev: process.env.NODE_ENV !== 'production' }); const handle = app.getRequestHandler(); @@ -41,7 +42,27 @@ const checkIsServerReady = (response) => { server.get('*', (req, res) => handle(req, res)); - await server.listen(port); + if (process.env.NEXT_SERVE_WITH_CUSTOM_CERTS) { + let options; + try { + options = { + key: fs.readFileSync( + process.cwd() + '/../../shared/src/server/localhost.key' + ), + cert: fs.readFileSync( + process.cwd() + '/../../shared/src/server/localhost.crt' + ), + }; + } catch (e) { + console.error( + 'No certificate file(s) found. Copy it from the local-proxy container.' + ); + return; + } + https.createServer(options, server).listen(port); + } else { + await server.listen(port); + } signalReady(); console.log(`> Ready on https://localhost:${port}`); // eslint-disable-line no-console })(); diff --git a/localdevelopment/benefit/nginx/html/500.html b/localdevelopment/benefit/nginx/html/500.html new file mode 100644 index 0000000000..7bc6d637d6 --- /dev/null +++ b/localdevelopment/benefit/nginx/html/500.html @@ -0,0 +1,56 @@ + + + + + Error 502 + + + + + + + +

ERROR 502

+

Waiting for web server, reloading in 5 ...

+ + + diff --git a/localdevelopment/benefit/nginx/nginx.conf b/localdevelopment/benefit/nginx/nginx.conf index 0189fff1e3..6975987534 100644 --- a/localdevelopment/benefit/nginx/nginx.conf +++ b/localdevelopment/benefit/nginx/nginx.conf @@ -4,21 +4,31 @@ http { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; + resolver 127.0.0.11 valid=30s; + server { listen 8000 ssl; server_name localhost; ssl_certificate localhost.crt; ssl_certificate_key localhost.key; + client_max_body_size 20M; + # Redirect http requests to https error_page 497 https://$host:$server_port$request_uri; - client_max_body_size 20M; + error_page 502 503 /500.html; + + location = /500.html { + root /etc/nginx/html; + internal; + } location / { + set $upstream_backend backend:8000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; - proxy_pass http://backend:8000; + proxy_pass http://$upstream_backend; } } server { @@ -28,21 +38,28 @@ http { ssl_certificate_key localhost.key; client_max_body_size 20M; error_page 497 302 =307 https://$host:$server_port$request_uri; + error_page 502 503 /500.html; + location = /500.html { + root /etc/nginx/html; + internal; + } # https://github.com/vercel/next.js/issues/30491#issuecomment-962835174 location /_next/webpack-hmr { - proxy_pass http://applicant:3000/_next/webpack-hmr; + set $upstream_applicant applicant:3000; + proxy_pass http://$upstream_applicant/_next/webpack-hmr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { + set $upstream_applicant applicant:3000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; - proxy_pass http://applicant:3000; + proxy_pass http://$upstream_applicant; } } server { @@ -52,21 +69,33 @@ http { ssl_certificate_key localhost.key; client_max_body_size 20M; error_page 497 302 =307 https://$host:$server_port$request_uri; + error_page 502 503 /500.html; + + location = /500.html { + root /etc/nginx/html; + internal; + } # https://github.com/vercel/next.js/issues/30491#issuecomment-962835174 location /_next/webpack-hmr { - proxy_pass http://handler:3100/_next/webpack-hmr; + set $upstream_handler handler:3100; + proxy_pass http://$upstream_handler/_next/webpack-hmr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { + set $upstream_handler handler:3100; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; - proxy_pass http://handler:3100; + proxy_pass http://$upstream_handler; } } + + error_page 404 /custom_404.html; + + }