Refactor how base API url is set on frontend

This commit is contained in:
Dana Lambert 2021-11-25 10:22:51 +13:00 committed by Alistair McIntyre
parent ecc6e9eabe
commit 043d89bd04
4 changed files with 17 additions and 23 deletions

View file

@ -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}
- 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"

View file

@ -1 +0,0 @@
export const API_URL = "http://localhost:8000/api";

View file

@ -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"] = "*";

View file

@ -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) {