From e99f12d2338d931aad96a06a6b095303bde989e8 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 3 May 2020 16:06:32 +0200 Subject: [PATCH] [mod] make `production` webapp work as well --- src/webapp/Index.vue | 2 +- src/webapp/api.js | 4 ++-- webpack.common.js | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/webapp/Index.vue b/src/webapp/Index.vue index 9dadd2b..d34c010 100644 --- a/src/webapp/Index.vue +++ b/src/webapp/Index.vue @@ -19,7 +19,7 @@ } }, async created() { - const dwatcherAPI = api('http://localhost:10501') + const dwatcherAPI = api() this.watchers = await dwatcherAPI.getStatus() }, diff --git a/src/webapp/api.js b/src/webapp/api.js index 4747241..802f2c7 100644 --- a/src/webapp/api.js +++ b/src/webapp/api.js @@ -1,9 +1,9 @@ import * as axios from "axios"; -export function api(baseURL) { +export function api() { const instance = axios.default.create({ - baseURL + baseURL: __API__ }) return { diff --git a/webpack.common.js b/webpack.common.js index 98dabf8..28cda30 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -1,8 +1,16 @@ +const webpack = require("webpack"); + const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const VueLoaderPlugin = require('vue-loader/lib/plugin') +let __API__ = "'http://localhost:10501'" + +if (process.env.NODE_ENV === 'production') { + __API__ = "'/'" +} + module.exports = { context: path.resolve(__dirname, './src/webapp/'), entry: './index.js', @@ -16,7 +24,10 @@ module.exports = { title: 'Output Management', template: 'index.html' }), - new VueLoaderPlugin() + new VueLoaderPlugin(), + new webpack.DefinePlugin({ + __API__ + }) ], module: { rules: [