From 8280d9e7e9366435d158ce503035dace1cc5d19e Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 13 Sep 2023 12:03:36 +0530 Subject: [PATCH] add env vars for local development --- Accounts/webpack.config.js | 129 +++++++++++++++++-------------- AdminDashboard/webpack.config.js | 3 + CommonUI/src/Config.ts | 4 +- Dashboard/webpack.config.js | 2 + StatusPage/webpack.config.js | 2 + 5 files changed, 79 insertions(+), 61 deletions(-) diff --git a/Accounts/webpack.config.js b/Accounts/webpack.config.js index 6330c450c1..e3a958d8b1 100644 --- a/Accounts/webpack.config.js +++ b/Accounts/webpack.config.js @@ -2,8 +2,9 @@ const path = require("path"); const webpack = require("webpack"); const dotenv = require('dotenv'); const express = require('express'); +const axios = require('axios'); -const readEnvFile = (pathToFile) => { +const readEnvFile = async (pathToFile) => { const parsed = dotenv.config({ path: pathToFile }).parsed; @@ -13,66 +14,76 @@ const readEnvFile = (pathToFile) => { env[key] = JSON.stringify(parsed[key]); } + env['HOST'] = 'localhost' // use localhost for dev. + env['USE_HTTPS'] = true; + + // Ping API and get respojse. + const response = await axios.get(`http://localhost/api/`); return env; } -module.exports = { - entry: "./src/Index.tsx", - mode: "development", - output: { - filename: "bundle.js", - path: path.resolve(__dirname, "public", "dist"), - publicPath: "/accounts/dist/", - }, - resolve: { - extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss'], - alias: { - react: path.resolve('./node_modules/react'), - } - }, - externals: { - 'react-native-sqlite-storage': 'react-native-sqlite-storage' - }, - plugins: [ - new webpack.DefinePlugin({ - 'process': { - 'env': { - ...readEnvFile('/usr/src/app/dev-env/.env') - } - } - }), - ], - module: { - rules: [ - { - test: /\.(ts|tsx)$/, - use: 'ts-loader' - }, - { - test: /\.s[ac]ss$/i, - use: ['style-loader', 'css-loader', "sass-loader"] - }, - { - test: /\.css$/i, - use: ['style-loader', 'css-loader'] - }, - { - test: /\.(jpe?g|png|gif|svg)$/i, - loader: 'file-loader' - } - ], - }, - devServer: { - historyApiFallback: true, - devMiddleware: { - writeToDisk: true, +const webpackConfig = async () => { + return { + entry: "./src/Index.tsx", + mode: "development", + output: { + filename: "bundle.js", + path: path.resolve(__dirname, "public", "dist"), + publicPath: "/accounts/dist/", }, - allowedHosts: "all", - setupMiddlewares: (middlewares, devServer) => { - devServer.app.use('/accounts/assets', express.static(path.resolve(__dirname, 'public', 'assets'))); - return middlewares; - } - }, - devtool: 'eval-source-map', -} \ No newline at end of file + resolve: { + extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss'], + alias: { + react: path.resolve('./node_modules/react'), + } + }, + externals: { + 'react-native-sqlite-storage': 'react-native-sqlite-storage' + }, + plugins: [ + new webpack.DefinePlugin({ + 'process': { + 'env': { + ...(await readEnvFile('/usr/src/app/dev-env/.env')) + } + } + }), + ], + module: { + rules: [ + { + test: /\.(ts|tsx)$/, + use: 'ts-loader' + }, + { + test: /\.s[ac]ss$/i, + use: ['style-loader', 'css-loader', "sass-loader"] + }, + { + test: /\.css$/i, + use: ['style-loader', 'css-loader'] + }, + { + test: /\.(jpe?g|png|gif|svg)$/i, + loader: 'file-loader' + } + ], + }, + devServer: { + historyApiFallback: true, + devMiddleware: { + writeToDisk: true, + }, + allowedHosts: "all", + setupMiddlewares: (middlewares, devServer) => { + devServer.app.use('/accounts/assets', express.static(path.resolve(__dirname, 'public', 'assets'))); + return middlewares; + } + }, + devtool: 'eval-source-map', + } +}; + + +module.exports = webpackConfig; \ No newline at end of file diff --git a/AdminDashboard/webpack.config.js b/AdminDashboard/webpack.config.js index 9f5b323e95..360f078198 100644 --- a/AdminDashboard/webpack.config.js +++ b/AdminDashboard/webpack.config.js @@ -13,6 +13,9 @@ const readEnvFile = (pathToFile) => { env[key] = JSON.stringify(parsed[key]); } + env['HOST'] = 'localhost' // use localhost for dev. + env['USE_HTTPS'] = true; + return env; } diff --git a/CommonUI/src/Config.ts b/CommonUI/src/Config.ts index 5773ca2270..6bf6368692 100644 --- a/CommonUI/src/Config.ts +++ b/CommonUI/src/Config.ts @@ -30,9 +30,9 @@ export const env: Function = (key: string): string => { }; export const HTTP_PROTOCOL: Protocol = - env('HTTP_PROTOCOL') === 'http' ? Protocol.HTTP : Protocol.HTTPS; + env('USE_HTTPS') === true ? Protocol.HTTP : Protocol.HTTPS; -export const HOST: string = env('DOMAIN') || ''; +export const HOST: string = env('HOST') || ''; export const BILLING_ENABLED: boolean = env('BILLING_ENABLED') === 'true'; export const BILLING_PUBLIC_KEY: string = env('BILLING_PUBLIC_KEY') || ''; diff --git a/Dashboard/webpack.config.js b/Dashboard/webpack.config.js index 4b12ae3fea..1154ebd608 100644 --- a/Dashboard/webpack.config.js +++ b/Dashboard/webpack.config.js @@ -13,6 +13,8 @@ const readEnvFile = (pathToFile) => { env[key] = JSON.stringify(parsed[key]); } + env['HOST'] = 'localhost' // use localhost for dev. + env['USE_HTTPS'] = true; return env; } diff --git a/StatusPage/webpack.config.js b/StatusPage/webpack.config.js index 5a23f9cc61..f2b7fdabd3 100644 --- a/StatusPage/webpack.config.js +++ b/StatusPage/webpack.config.js @@ -13,6 +13,8 @@ const readEnvFile = (pathToFile) => { env[key] = JSON.stringify(parsed[key]); } + env['HOST'] = 'localhost' // use localhost for dev. + env['USE_HTTPS'] = true; return env; }