From af084e84af83236e440291ef7663c8d05e41bd19 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 16 Jul 2022 14:02:14 +0300 Subject: [PATCH] configs changes --- config.js | 12 +++++++++++- src/features/releaseNotes/actionCreators.js | 2 +- webpack.config.dev.js | 8 ++------ webpack.config.prod.js | 17 +++-------------- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/config.js b/config.js index efc7e91..31f4240 100644 --- a/config.js +++ b/config.js @@ -1,4 +1,5 @@ const dev = { + NODE_ENV: "development", REVERSE_PROXY_API_URL: "http://localhost:5050", CHATBOT_API_URL: "http://localhost:5061", REVERSE_PROXY_DOCS_URL: "https://toodle.ddns.net/hedgedoc/s/UkJ6S5NJz" @@ -12,4 +13,13 @@ const prod = { REVERSE_PROXY_DOCS_URL: "https://toodle.ddns.net/hedgedoc/s/UkJ6S5NJz" }; -module.exports = { dev, prod }; +const getConfig = env => { + const config = env === "prod" ? prod : dev; + let configs = {}; + Object.keys(config).forEach(z => { + configs[`process.env.${z}`] = JSON.stringify(config[z]); + }); + return configs; +}; + +module.exports = getConfig; diff --git a/src/features/releaseNotes/actionCreators.js b/src/features/releaseNotes/actionCreators.js index dc45b6b..836bbbd 100644 --- a/src/features/releaseNotes/actionCreators.js +++ b/src/features/releaseNotes/actionCreators.js @@ -3,7 +3,7 @@ import api from "./api"; import { sendHttpRequest } from "../../redux/actions/httpActions"; export function loadReleaseNotes() { - return async function (dispatch, getState) { + return async function(dispatch, getState) { try { const notes = getState().releaseNotes; if (notes && (notes.loading || notes.loaded)) return; diff --git a/webpack.config.dev.js b/webpack.config.dev.js index ea7e902..d3386ff 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -1,14 +1,10 @@ const webpack = require("webpack"); const path = require("path"); -const config = require("./config"); +const getConfig = require("./config"); const HtmlWebpackPlugin = require("html-webpack-plugin"); process.env.NODE_ENV = "development"; - -let configs = {}; -Object.keys(config.dev).forEach(z => { - configs[`process.env.${z}`] = JSON.stringify(config.dev[z]); -}); +const configs = getConfig("dev"); module.exports = { mode: "development", diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 4cfa045..e6a9ee8 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -4,9 +4,11 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const webpackBundleAnalyzer = require("webpack-bundle-analyzer"); const CopyPlugin = require("copy-webpack-plugin"); +const getConfig = require("./config"); process.env.NODE_ENV = "production"; process.env.PUBLIC_URL = "/reverse-proxy"; +const configs = getConfig("prod"); module.exports = { mode: "production", @@ -26,20 +28,7 @@ module.exports = { filename: "[name].[contenthash].css" }), - new webpack.DefinePlugin({ - // This global makes sure React is built in prod mode. - "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV), - "process.env.PUBLIC_URL": JSON.stringify(process.env.PUBLIC_URL), - "process.env.REVERSE_PROXY_API_URL": JSON.stringify( - "https://toodle.ddns.net/reverse-proxy-api" - ), - "process.env.CHATBOT_API_URL": JSON.stringify( - "https://toodle.ddns.net/chatbot-api" - ), - "process.env.REVERSE_PROXY_DOCS_URL": JSON.stringify( - "https://toodle.ddns.net/docs/books/reverse-proxy" - ) - }), + new webpack.DefinePlugin(configs), new HtmlWebpackPlugin({ template: "src/index.html", favicon: "src/favicon.ico",