From 0933132a423a7c2b317b750b354b37e6abaa7893 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Fri, 27 Sep 2024 18:21:50 +0200 Subject: [PATCH] Set api url for prod --- frontend/src/services/api.js | 2 +- frontend/webpack.config.js | 78 ++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index 02e0355..e1155b3 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -1,4 +1,4 @@ -const API_BASE_URL = 'http://localhost:8080/api/v1'; +const API_BASE_URL = window.API_BASE_URL; export const fetchFileList = async () => { try { diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index d97e0d0..4448a94 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -1,39 +1,49 @@ const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); +const webpack = require('webpack'); -module.exports = { - entry: './src/index.js', - output: { - path: path.resolve(__dirname, 'dist'), - filename: 'bundle.js', - }, - module: { - rules: [ - { - test: /\.(js|jsx)$/, - exclude: /node_modules/, - use: ['babel-loader'], - }, - { - test: /\.scss$/, - use: ['style-loader', 'css-loader', 'sass-loader'], - }, - { - test: /\.css$/, - use: ['style-loader', 'css-loader'], - }, - ], - }, - plugins: [ - new HtmlWebpackPlugin({ - template: './public/index.html', - }), - ], - devServer: { - static: { - directory: path.join(__dirname, 'public'), +module.exports = (env, argv) => { + const isProduction = argv.mode === 'production'; + + return { + entry: './src/index.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'bundle.js', }, - port: 3000, - open: true, - }, + module: { + rules: [ + { + test: /\.(js|jsx)$/, + exclude: /node_modules/, + use: ['babel-loader'], + }, + { + test: /\.scss$/, + use: ['style-loader', 'css-loader', 'sass-loader'], + }, + { + test: /\.css$/, + use: ['style-loader', 'css-loader'], + }, + ], + }, + plugins: [ + new HtmlWebpackPlugin({ + template: './public/index.html', + }), + new webpack.DefinePlugin({ + 'window.API_BASE_URL': JSON.stringify( + isProduction ? '/api/v1' : 'http://localhost:8080/api/v1' + ), + }), + ], + devServer: { + static: { + directory: path.join(__dirname, 'public'), + }, + port: 3000, + open: true, + }, + }; }; \ No newline at end of file