From f712e7f75fc90ac30b0f8b33365bc3792614992d Mon Sep 17 00:00:00 2001 From: Marion Date: Mon, 23 Sep 2024 09:20:10 +0200 Subject: [PATCH] prepare config for backend api call -> WIP --- .env.sample | 6 ++++-- Dockerfile | 6 ++++-- Makefile | 6 ++++-- nginx/default.conf | 18 +++++++++--------- src/assets/configs/config.json.tmpl | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.env.sample b/.env.sample index 6c23818e..29e022c7 100644 --- a/.env.sample +++ b/.env.sample @@ -1,7 +1,9 @@ # the base_href if you're serving your front in an url like www.example.com/geoshop FRONT_HREF=/geoshop -API_BASE_URL=http://localhost:5007 +# API_BASE_URL=http://localhost:5007 +API_BASE_URL=http://localhost:8000/ # the base href of your backend ROOTURL=/geoshop_api # where are metadata and product images? This is concatenated with relative paths coming from backend -MEDIA_URL=https://some.server.com/geoshop_media +# MEDIA_URL=https://some.server.com/geoshop_media +MEDIA_URL= diff --git a/Dockerfile b/Dockerfile index a8c3a2e0..694e92c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,13 @@ FROM node:22.6.0-slim AS builder # Accept build arguments and set them as environment variables -ARG API_URL +ARG API_BASE_URL +ARG API_ROOTURL ARG MEDIA_URL ARG GEOCODER_URL -ENV API_URL=${API_URL} ENV MEDIA_URL=${MEDIA_URL} +ENV API_BASE_URL=${API_BASE_URL} +ENV API_ROOTURL=${API_ROOTURL} WORKDIR /usr/app diff --git a/Makefile b/Makefile index 34164f31..230a739f 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,8 @@ build: install ## Build npm project build_docker: ## Build docker image docker build --tag=camptocamp/geoshop-front:$(VERSION) \ --build-arg=VERSION=$(VERSION) \ - --build-arg=API_URL=$(API_URL) \ + --build-arg=API_BASE_URL=$(API_BASE_URL) \ + --build-arg=API_ROOTURL=$(API_ROOTURL) \ --build-arg=MEDIA_URL=$(MEDIA_URL) . docker tag camptocamp/geoshop-front:$(VERSION) camptocamp/geoshop-front:$(DOCKER_TAG) @@ -31,7 +32,8 @@ build_docker: ## Build docker image build_ghcr: ## Build docker image tagged for GHCR docker build --tag=ghcr.io/camptocamp/geoshop-front:$(VERSION) \ --build-arg=VERSION=$(VERSION) \ - --build-arg=API_URL=$(API_URL) \ + --build-arg=API_BASE_URL=$(API_BASE_URL) \ + --build-arg=API_ROOTURL=$(API_ROOTURL) \ --build-arg=MEDIA_URL=$(MEDIA_URL) . docker tag ghcr.io/camptocamp/geoshop-front:$(VERSION) ghcr.io/camptocamp/geoshop-front:$(DOCKER_TAG) diff --git a/nginx/default.conf b/nginx/default.conf index 999eb795..25f358bf 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -19,13 +19,13 @@ server { # TODO calling the backend internaly does not work on localhost: How to in K8S? # This is needed for the FE to be able to call the BE - # location /localhost/ { - # # Remove /api prefix and forward to geoportal - # rewrite ^/localhost/(.*)$ /$1 break; - # proxy_pass http://localhost:8000/; - # proxy_set_header Host $host; - # proxy_set_header X-Real-IP $remote_addr; - # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - # proxy_set_header X-Forwarded-Proto $scheme; - # } + location /geoshop_api/ { + # Remove /api prefix and forward to geoportal + rewrite ^/localhost/(.*)$ /$1 break; + proxy_pass http://localhost:8000/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } } \ No newline at end of file diff --git a/src/assets/configs/config.json.tmpl b/src/assets/configs/config.json.tmpl index c67900a7..5a9fedf9 100644 --- a/src/assets/configs/config.json.tmpl +++ b/src/assets/configs/config.json.tmpl @@ -1,5 +1,5 @@ { - "apiUrl": "${API_URL}", + "apiUrl": "${API_BASE_URL}/${API_ROOTURL}", "mediaUrl": "${MEDIA_URL}", "baseMapUrl": "https://wmts.geo.admin.ch/1.0.0/{layer}/{style}/current/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}", "geocoderUrl": "https://nominatim.openstreetmap.org/search",