Selaa lähdekoodia

feat(webapp): make env available as constants in JS code

Nils Wisiol 5 vuotta sitten
vanhempi
commit
44bfd34437
6 muutettua tiedostoa jossa 17 lisäystä ja 7 poistoa
  1. 2 2
      docker-compose.dev.yml
  2. 4 2
      docker-compose.yml
  3. 1 0
      webapp/.gitignore
  4. 6 0
      webapp/Dockerfile
  5. 2 0
      webapp/src/env.js.template
  6. 2 3
      webapp/vue.config.js

+ 2 - 2
docker-compose.dev.yml

@@ -58,12 +58,12 @@ services:
       driver: "json-file"
 
   webapp:
-    image: node:latest
     volumes:
     - ./webapp/:/usr/src/app/
     working_dir: /usr/src/app/
-    command: npm run serve --fix
+    command: bash -c "cat src/env.js.template | envsubst > src/env.js && npm run serve --fix"
     environment:
+    - DESECSTACK_DOMAIN
     - HOST=0.0.0.0
     - PORT=443
     networks:

+ 4 - 2
docker-compose.yml

@@ -182,12 +182,14 @@ services:
     restart: unless-stopped
 
   webapp:
-    image: node:latest
+    build: webapp
+    environment:
+    - DESECSTACK_DOMAIN
     volumes:
     - ./webapp/:/usr/src/app/
     - webapp_dist:/usr/src/app/dist
     working_dir: /usr/src/app/
-    command: bash -c "npm install && npm run build -- --no-clean"
+    command: bash -c "cat src/env.js.template | envsubst > src/env.js && npm install && npm run build -- --no-clean"
     logging:
       driver: "syslog"
       options:

+ 1 - 0
webapp/.gitignore

@@ -8,6 +8,7 @@ node_modules
 # local env files
 .env.local
 .env.*.local
+src/env.js
 
 # Log files
 npm-debug.log*

+ 6 - 0
webapp/Dockerfile

@@ -0,0 +1,6 @@
+FROM node:latest
+RUN \
+  apt-get update \
+  && apt-get -y install gettext-base \
+  && apt-get clean \
+  && rm -rf /var/lib/apt/lists/*

+ 2 - 0
webapp/src/env.js.template

@@ -0,0 +1,2 @@
+export const DESECSTACK_DOMAIN = '${DESECSTACK_DOMAIN}';
+export const LOCAL_PUBLIC_SUFFIXES = ['dedyn.${DESECSTACK_DOMAIN}'];

+ 2 - 3
webapp/vue.config.js

@@ -2,9 +2,8 @@ module.exports = {
   configureWebpack: {
     devServer: {
       disableHostCheck: true,
-      sockHost: 'desec.example.dedyn.io',    // TODO use env
-      public: 'https://desec.example.dedyn.io/app/',    // TODO use env
-      // sockPath: "/app/sockjs-node",
+      sockHost: 'desec.' + process.env.DESECSTACK_DOMAIN,
+      public: 'https://desec.' + process.env.DESECSTACK_DOMAIN + '/app/',
     },
   },
   publicPath: '/app/',