Skip to content

Commit

Permalink
fix: add frontend dynamic env using nginx ssi
Browse files Browse the repository at this point in the history
  • Loading branch information
achauve committed Aug 2, 2024
1 parent 49c937d commit 37334cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
33 changes: 14 additions & 19 deletions packages/frontend-usagers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,25 @@ COPY packages/frontend-usagers/package.json packages/frontend-usagers/yarn.lock
RUN yarn workspace @vao/frontend-usagers install --frozen-lockfile

# these variables are needed at build time because we produce a *static* app
ARG NUXT_PUBLIC_APP_VERSION=development
ARG NUXT_PUBLIC_BACKEND_URL
ARG NUXT_PUBLIC_ENVIRONMENT
ARG NUXT_PUBLIC_MATOMO_ENABLED
ARG NUXT_PUBLIC_MATOMO_HOST
ARG NUXT_PUBLIC_MATOMO_SITE_ID
ARG NUXT_PUBLIC_SENTRY_DSN
ARG NUXT_PUBLIC_SENTRY_RELEASE
ARG NUXT_PUBLIC_SENTRY_ENABLED

ARG SENTRY_ORG
ARG SENTRY_PROJECT
ARG SENTRY_URL
ARG SENTRY_AUTH_TOKEN

ENV NUXT_PUBLIC_APP_VERSION=$NUXT_PUBLIC_APP_VERSION
ENV NUXT_PUBLIC_BACKEND_URL=$NUXT_PUBLIC_BACKEND_URL
ENV NUXT_PUBLIC_ENVIRONMENT=$NUXT_PUBLIC_ENVIRONMENT
ENV NUXT_PUBLIC_MATOMO_ENABLED=$NUXT_PUBLIC_MATOMO_ENABLED
ENV NUXT_PUBLIC_MATOMO_HOST=$NUXT_PUBLIC_MATOMO_HOST
ENV NUXT_PUBLIC_MATOMO_SITE_ID=$NUXT_PUBLIC_MATOMO_SITE_ID
ENV NUXT_PUBLIC_SENTRY_DSN=$NUXT_PUBLIC_SENTRY_DSN
ENV NUXT_PUBLIC_SENTRY_RELEASE=$NUXT_PUBLIC_SENTRY_RELEASE
ENV NUXT_PUBLIC_SENTRY_ENABLED=$NUXT_PUBLIC_SENTRY_ENABLED
ENV SENTRY_RELEASE=$NUXT_PUBLIC_SENTRY_RELEASE
# Runtime env variables set by Nginx injection
ENV NUXT_PUBLIC_APP_VERSION=ENV_NUXT_PUBLIC_APP_VERSION
ENV NUXT_PUBLIC_BACKEND_URL=ENV_NUXT_PUBLIC_BACKEND_URL
ENV NUXT_PUBLIC_ENVIRONMENT=ENV_NUXT_PUBLIC_ENVIRONMENT
ENV NUXT_PUBLIC_MATOMO_ENABLED=ENV_NUXT_PUBLIC_MATOMO_ENABLED
ENV NUXT_PUBLIC_MATOMO_HOST=ENV_NUXT_PUBLIC_MATOMO_HOST
ENV NUXT_PUBLIC_MATOMO_SITE_ID=ENV_NUXT_PUBLIC_MATOMO_SITE_ID
ENV NUXT_PUBLIC_SENTRY_DSN=ENV_NUXT_PUBLIC_SENTRY_DSN
ENV NUXT_PUBLIC_SENTRY_ENABLED=ENV_NUXT_PUBLIC_SENTRY_ENABLED

# Cannot be changed at runtime
ENV NUXT_PUBLIC_SENTRY_RELEASE=$SENTRY_RELEASE
ENV SENTRY_RELEASE=$SENTRY_RELEASE
ENV SENTRY_ORG=$SENTRY_ORG
ENV SENTRY_PROJECT=$SENTRY_PROJECT
ENV SENTRY_URL=$SENTRY_URL
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend-usagers/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ http {
location / {
# this always fallback on /index.html, never 404
try_files $uri $uri.html $uri/index.html $uri/ /index.html;

ssi on;
set $ENV_NUXT_PUBLIC_APP_VERSION "$ENV_NUXT_PUBLIC_APP_VERSION";
set $ENV_NUXT_PUBLIC_BACKEND_URL "$ENV_NUXT_PUBLIC_BACKEND_URL";
set $ENV_NUXT_PUBLIC_ENVIRONMENT "$ENV_NUXT_PUBLIC_ENVIRONMENT";
set $ENV_NUXT_PUBLIC_MATOMO_ENABLED "$ENV_NUXT_PUBLIC_MATOMO_ENABLED";
set $ENV_NUXT_PUBLIC_MATOMO_HOST "$ENV_NUXT_PUBLIC_MATOMO_HOST";
set $ENV_NUXT_PUBLIC_MATOMO_SITE_ID "$ENV_NUXT_PUBLIC_MATOMO_SITE_ID";
set $ENV_NUXT_PUBLIC_SENTRY_DSN "$ENV_NUXT_PUBLIC_SENTRY_DSN";
set $ENV_NUXT_PUBLIC_SENTRY_ENABLED "$ENV_NUXT_PUBLIC_SENTRY_ENABLED";
}

location /50x.html {
Expand Down

0 comments on commit 37334cc

Please sign in to comment.