Set api url for prod

This commit is contained in:
2024-09-27 18:21:50 +02:00
parent 56bd2c29ad
commit 0933132a42
2 changed files with 45 additions and 35 deletions

View File

@@ -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 () => { export const fetchFileList = async () => {
try { try {

View File

@@ -1,7 +1,11 @@
const path = require('path'); const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = { module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
return {
entry: './src/index.js', entry: './src/index.js',
output: { output: {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
@@ -28,6 +32,11 @@ module.exports = {
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './public/index.html', template: './public/index.html',
}), }),
new webpack.DefinePlugin({
'window.API_BASE_URL': JSON.stringify(
isProduction ? '/api/v1' : 'http://localhost:8080/api/v1'
),
}),
], ],
devServer: { devServer: {
static: { static: {
@@ -37,3 +46,4 @@ module.exports = {
open: true, open: true,
}, },
}; };
};