From 043d89bd04da15b06dd2eb04aa027fede902153d Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Thu, 25 Nov 2021 10:22:51 +1300 Subject: [PATCH] Refactor how base API url is set on frontend --- docker-compose.yaml | 22 +++++++++++++++------- frontend/src/config.js | 1 - frontend/src/repository/Repository.js | 6 +----- nginx.conf | 11 +---------- 4 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 frontend/src/config.js diff --git a/docker-compose.yaml b/docker-compose.yaml index 557cab9..f0c3ed0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,23 +10,19 @@ services: build: context: backend dockerfile: Dockerfile - container_name: righttree-backend + container_name: backend depends_on: - postgres volumes: - ./backend:/app environment: - LINZ_API_KEY=${LINZ_API_KEY} - ports: - - "8000:8000" command: bash -c "./manage.py runserver 0.0.0.0:8000" frontend: image: node:16-alpine3.11 restart: unless-stopped - container_name: righttree-frontend - ports: - - "3000:3000" + container_name: frontend volumes: - ./frontend:/app working_dir: /app @@ -44,4 +40,16 @@ services: environment: - POSTGRES_DB=${POSTGRES_DB} - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \ No newline at end of file + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + + nginx: + container_name: nginx + image: nginx + depends_on: + - postgres + - backend + - frontend + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + ports: + - "9000:80" diff --git a/frontend/src/config.js b/frontend/src/config.js deleted file mode 100644 index 60399ab..0000000 --- a/frontend/src/config.js +++ /dev/null @@ -1 +0,0 @@ -export const API_URL = "http://localhost:8000/api"; diff --git a/frontend/src/repository/Repository.js b/frontend/src/repository/Repository.js index 135c84b..9a697ab 100644 --- a/frontend/src/repository/Repository.js +++ b/frontend/src/repository/Repository.js @@ -1,12 +1,8 @@ import axios from "axios" -import { API_URL } from "../config"; - -// Base URL used by all requests -const baseUrl = API_URL; // Create the axios object const repo = axios.create({ - baseURL: baseUrl, + baseURL: "/api", }); repo.defaults.headers.post["access-control-allow-origin"] = "*"; diff --git a/nginx.conf b/nginx.conf index 848fc20..8db9391 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,20 +1,11 @@ http { server { listen 80; - listen 443 ssl; - index index.html; include /etc/nginx/mime.types; proxy_set_header Host $http_host; - ssl_certificate /etc/ssl/private/nginx/selfsigned.crt; - ssl_certificate_key /etc/ssl/private/nginx/selfsigned.key; - location / { - root /etc/nginx/html/build; - } - - location /staticfiles { - root /etc/nginx/html/; + proxy_pass http://frontend:3000; } location ~* ^/(api|admin) {