Refactor how base API url is set on frontend
This commit is contained in:
parent
ecc6e9eabe
commit
043d89bd04
4 changed files with 17 additions and 23 deletions
|
@ -10,23 +10,19 @@ services:
|
||||||
build:
|
build:
|
||||||
context: backend
|
context: backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: righttree-backend
|
container_name: backend
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend:/app
|
- ./backend:/app
|
||||||
environment:
|
environment:
|
||||||
- LINZ_API_KEY=${LINZ_API_KEY}
|
- LINZ_API_KEY=${LINZ_API_KEY}
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
command: bash -c "./manage.py runserver 0.0.0.0:8000"
|
command: bash -c "./manage.py runserver 0.0.0.0:8000"
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
image: node:16-alpine3.11
|
image: node:16-alpine3.11
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
container_name: righttree-frontend
|
container_name: frontend
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./frontend:/app
|
- ./frontend:/app
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
|
@ -44,4 +40,16 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_DB=${POSTGRES_DB}
|
- POSTGRES_DB=${POSTGRES_DB}
|
||||||
- POSTGRES_USER=${POSTGRES_USER}
|
- 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"
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
export const API_URL = "http://localhost:8000/api";
|
|
|
@ -1,12 +1,8 @@
|
||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { API_URL } from "../config";
|
|
||||||
|
|
||||||
// Base URL used by all requests
|
|
||||||
const baseUrl = API_URL;
|
|
||||||
|
|
||||||
// Create the axios object
|
// Create the axios object
|
||||||
const repo = axios.create({
|
const repo = axios.create({
|
||||||
baseURL: baseUrl,
|
baseURL: "/api",
|
||||||
});
|
});
|
||||||
|
|
||||||
repo.defaults.headers.post["access-control-allow-origin"] = "*";
|
repo.defaults.headers.post["access-control-allow-origin"] = "*";
|
||||||
|
|
11
nginx.conf
11
nginx.conf
|
@ -1,20 +1,11 @@
|
||||||
http {
|
http {
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
listen 443 ssl;
|
|
||||||
index index.html;
|
|
||||||
include /etc/nginx/mime.types;
|
include /etc/nginx/mime.types;
|
||||||
proxy_set_header Host $http_host;
|
proxy_set_header Host $http_host;
|
||||||
|
|
||||||
ssl_certificate /etc/ssl/private/nginx/selfsigned.crt;
|
|
||||||
ssl_certificate_key /etc/ssl/private/nginx/selfsigned.key;
|
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
root /etc/nginx/html/build;
|
proxy_pass http://frontend:3000;
|
||||||
}
|
|
||||||
|
|
||||||
location /staticfiles {
|
|
||||||
root /etc/nginx/html/;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* ^/(api|admin) {
|
location ~* ^/(api|admin) {
|
||||||
|
|
Loading…
Reference in a new issue