Added support for env vars in nginx.conf.template and fixed websocket proxy

This commit is contained in:
Clément Le Bihan
2023-03-29 17:01:58 +02:00
parent e9f6adab63
commit 8784e8de3c
4 changed files with 36 additions and 25 deletions

View File

@@ -39,6 +39,10 @@ services:
args:
- API_URL=${API_URL}
- SCORO_URL=${SCORO_URL}
environment:
- API_URL=http://back:3000/
- SCOROMETER_URL=http://scorometer:6543/
- NGINX_PORT=80
ports:
- "80:80"
depends_on:

View File

@@ -3,12 +3,14 @@
# Build the app
FROM node:16-alpine as build
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install
# install expo cli
RUN yarn global add expo-cli@6.0.5
# add sharp-cli (^2.1.0) for faster image processing
RUN yarn global add sharp-cli@^2.1.0
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
ARG API_URL
ENV API_URL=$API_URL
@@ -20,4 +22,6 @@ RUN expo build:web
# Serve the app
FROM nginx:1.21-alpine
COPY --from=build /app/web-build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf.template /etc/nginx/conf.d/default.conf.template
CMD envsubst '$API_URL $SCOROMETER_URL $NGINX_PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'

View File

@@ -1,22 +0,0 @@
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://back:3000/;
}
location /ws/ {
proxy_pass http://scorometer:6543/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}

25
front/nginx.conf.template Normal file
View File

@@ -0,0 +1,25 @@
server {
listen ${NGINX_PORT};
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass ${API_URL};
}
location /ws {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass ${SCOROMETER_URL};
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
}
}