From 022d78e76c3a5eacba0777019bf64fbf99c81215 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 15 May 2024 07:53:42 +0200 Subject: [PATCH] hotFix: fix env --- docker-compose.yml | 1 + front/Dockerfile | 3 +- front/env.template.js | 3 ++ front/nginx-entrypoint.sh | 7 +++++ front/salix/index.ejs | 2 ++ gulpfile.js | 9 ++++++ package.json | 2 ++ pnpm-lock.yaml | 60 ++++++++++++++++++++++++++++++++++++++- webpack.config.js | 3 -- 9 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 front/env.template.js create mode 100644 front/nginx-entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml index 5bb168093..ec40311c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: context: front environment: - TZ + - NODE_ENV ports: - 80 deploy: diff --git a/front/Dockerfile b/front/Dockerfile index c507d863c..e0a43c412 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -14,5 +14,6 @@ COPY nginx.conf sites-available/salix RUN rm sites-enabled/default && ln -s ../sites-available/salix sites-enabled/salix COPY dist /salix/dist +COPY nginx-entrypoint.sh / -CMD ["nginx", "-g", "daemon off;"] +ENTRYPOINT [ "sh", "/nginx-entrypoint.sh" ] diff --git a/front/env.template.js b/front/env.template.js new file mode 100644 index 000000000..dbeb2f67b --- /dev/null +++ b/front/env.template.js @@ -0,0 +1,3 @@ +window.process = { + env: {NODE_ENV: '${NODE_ENV}'} +}; diff --git a/front/nginx-entrypoint.sh b/front/nginx-entrypoint.sh new file mode 100644 index 000000000..b931ae77a --- /dev/null +++ b/front/nginx-entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +WWW_DIR=/usr/share/nginx/html +INJECT_FILE_SRC="${WWW_DIR}/env.template.js" +INJECT_FILE_DST="${WWW_DIR}/env.js" +envsubst < "${INJECT_FILE_SRC}" > "${INJECT_FILE_DST}" +[ -z "$@" ] && nginx -g 'daemon off;' || $@ diff --git a/front/salix/index.ejs b/front/salix/index.ejs index 3aed9d9a6..87a59ef86 100644 --- a/front/salix/index.ejs +++ b/front/salix/index.ejs @@ -5,6 +5,8 @@ + diff --git a/gulpfile.js b/gulpfile.js index aa2b65bc1..adfa66715 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -138,6 +138,9 @@ function webpack(done) { webpack.description = `Transpiles application into files`; function webpackDevServer(done) { + const replace = require('gulp-replace'); + const rename = require('gulp-rename'); + const webpack = require('webpack'); const merge = require('webpack-merge'); const WebpackDevServer = require('webpack-dev-server'); @@ -147,6 +150,12 @@ function webpackDevServer(done) { let devServer = wpConfig.devServer; + // local env + gulp.src(srcDir + '/env.template.js') + .pipe(replace('${NODE_ENV}', 'development')) + .pipe(rename('env.js')) + .pipe(gulp.dest(buildDir)); + for (let entryName in wpConfig.entry) { let entry = wpConfig.entry[entryName]; if (!Array.isArray(entry)) diff --git a/package.json b/package.json index 033eafc40..ced56412b 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "ftps": "^1.2.0", "gm": "^1.25.0", "got": "^10.7.0", + "gulp-rename": "^2.0.0", + "gulp-replace": "^1.1.4", "helmet": "^3.21.2", "i18n": "^0.8.4", "imap": "^0.8.19", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d3959ac03..4c0d4924b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,12 @@ dependencies: got: specifier: ^10.7.0 version: 10.7.0 + gulp-rename: + specifier: ^2.0.0 + version: 2.0.0 + gulp-replace: + specifier: ^1.1.4 + version: 1.1.4 helmet: specifier: ^3.21.2 version: 3.23.3 @@ -2629,6 +2635,10 @@ packages: resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} dev: true + /@types/expect@1.20.4: + resolution: {integrity: sha512-Q5Vn3yjTDyCMV50TB6VRIbQNxSE4OmZR86VSbGaNpfUolm0iePBB4KdEEHmxoY5sT2+2DIvXW0rvMDP2nHZ4Mg==} + dev: false + /@types/express-serve-static-core@4.17.42: resolution: {integrity: sha512-ckM3jm2bf/MfB3+spLPWYPUH573plBFwpOhqQ2WottxYV85j1HQFlxmnTq57X1yHY9awZPig06hL/cLMgNWHIQ==} dependencies: @@ -2787,6 +2797,13 @@ packages: resolution: {integrity: sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==} dev: false + /@types/vinyl@2.0.12: + resolution: {integrity: sha512-Sr2fYMBUVGYq8kj3UthXFAu5UN6ZW+rYr4NACjZQJvHvj+c8lYv0CahmZ2P/r7iUkN44gGUBwqxZkrKXYPb7cw==} + dependencies: + '@types/expect': 1.20.4 + '@types/node': 20.11.16 + dev: false + /@types/yargs-parser@21.0.3: resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} dev: true @@ -3767,6 +3784,11 @@ packages: engines: {node: '>=8'} dev: true + /binaryextensions@2.3.0: + resolution: {integrity: sha512-nAihlQsYGyc5Bwq6+EsubvANYGExeJKHDO3RjnvwU042fawQTQfM3Kxn7IHUXQOz4bzfwsGYYHGSvXyW4zOGLg==} + engines: {node: '>=0.8'} + dev: false + /bindings@1.5.0: resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==} requiresBuild: true @@ -7087,6 +7109,22 @@ packages: map-stream: 0.0.7 dev: true + /gulp-rename@2.0.0: + resolution: {integrity: sha512-97Vba4KBzbYmR5VBs9mWmK+HwIf5mj+/zioxfZhOKeXtx5ZjBk57KFlePf5nxq9QsTtFl0ejnHE3zTC9MHXqyQ==} + engines: {node: '>=4'} + dev: false + + /gulp-replace@1.1.4: + resolution: {integrity: sha512-SVSF7ikuWKhpAW4l4wapAqPPSToJoiNKsbDoUnRrSgwZHH7lH8pbPeQj1aOVYQrbZKhfSVBxVW+Py7vtulRktw==} + engines: {node: '>=10'} + dependencies: + '@types/node': 20.11.16 + '@types/vinyl': 2.0.12 + istextorbinary: 3.3.0 + replacestream: 4.0.3 + yargs-parser: 21.1.1 + dev: false + /gulp-util@3.0.8: resolution: {integrity: sha512-q5oWPc12lwSFS9h/4VIjG+1NuNDlJ48ywV2JKItY4Ycc/n1fXJeYPVQsfu5ZrhQi7FGSDBalwUCLar/GyHXKGw==} engines: {node: '>=0.10'} @@ -8321,6 +8359,14 @@ packages: istanbul-lib-report: 3.0.1 dev: true + /istextorbinary@3.3.0: + resolution: {integrity: sha512-Tvq1W6NAcZeJ8op+Hq7tdZ434rqnMx4CCZ7H0ff83uEloDvVbqAwaMTZcafKGJT0VHkYzuXUiCY4hlXQg6WfoQ==} + engines: {node: '>=8'} + dependencies: + binaryextensions: 2.3.0 + textextensions: 3.3.0 + dev: false + /jackspeak@2.3.6: resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} engines: {node: '>=14'} @@ -10783,7 +10829,6 @@ packages: /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} - dev: true /object-copy@0.1.0: resolution: {integrity: sha512-79LYn6VAb63zgtmAteVOWo9Vdj71ZVBy3Pbse+VqxDpEP83XuujMrGqHIwAXJ5I/aM0zU7dIyIAhifVTPrNItQ==} @@ -12058,6 +12103,14 @@ packages: remove-trailing-separator: 1.1.0 dev: true + /replacestream@4.0.3: + resolution: {integrity: sha512-AC0FiLS352pBBiZhd4VXB1Ab/lh0lEgpP+GGvZqbQh8a5cmXVoTe5EX/YeTFArnp4SRGTHh1qCHu9lGs1qG8sA==} + dependencies: + escape-string-regexp: 1.0.5 + object-assign: 4.1.1 + readable-stream: 2.3.8 + dev: false + /request@2.88.2: resolution: {integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==} engines: {node: '>= 6'} @@ -13556,6 +13609,11 @@ packages: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} dev: true + /textextensions@3.3.0: + resolution: {integrity: sha512-mk82dS8eRABNbeVJrEiN5/UMSCliINAuz8mkUwH4SwslkNP//gbEzlWNS5au0z5Dpx40SQxzqZevZkn+WYJ9Dw==} + engines: {node: '>=8'} + dev: false + /throat@5.0.0: resolution: {integrity: sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==} dev: true diff --git a/webpack.config.js b/webpack.config.js index 7296a62d1..5c5ca0a55 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -99,9 +99,6 @@ let baseConfig = { filename: 'index.html', chunks: ['salix'] }), - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify(env) - }) ], devtool: 'source-map', stats: {