From e204f6b81a1dff8e2335f4794992acece1a08b3d Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Tue, 03 Jun 2025 20:55:03 +0000
Subject: [PATCH] fixing paths for prod

---
 package-lock.json            |   13 ++++++
 vue/src/router.js            |   12 +++---
 vue/src/App.vue              |    2 
 package.json                 |    1 
 vue/.env.example             |    3 +
 vue/src/pages/KursDetail.vue |    3 -
 vite.config.js               |   53 ++++++++++++++++----------
 7 files changed, 56 insertions(+), 31 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 08df5f0..6649d9f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10,6 +10,7 @@
       "dependencies": {
         "@fastify/static": "^8.2.0",
         "@vueuse/core": "^13.3.0",
+        "dotenv": "^16.5.0",
         "fastify": "^5.3.3",
         "lodash": "^4.17.21",
         "mysql2": "^3.14.1",
@@ -2375,6 +2376,18 @@
         "node": ">=6"
       }
     },
+    "node_modules/dotenv": {
+      "version": "16.5.0",
+      "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",
+      "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==",
+      "license": "BSD-2-Clause",
+      "engines": {
+        "node": ">=12"
+      },
+      "funding": {
+        "url": "https://dotenvx.com"
+      }
+    },
     "node_modules/eastasianwidth": {
       "version": "0.2.0",
       "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
diff --git a/package.json b/package.json
index 64e72e9..35960e7 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
   "dependencies": {
     "@fastify/static": "^8.2.0",
     "@vueuse/core": "^13.3.0",
+    "dotenv": "^16.5.0",
     "fastify": "^5.3.3",
     "lodash": "^4.17.21",
     "mysql2": "^3.14.1",
diff --git a/vite.config.js b/vite.config.js
index cffc08d..4a0d867 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -1,29 +1,40 @@
-import { fileURLToPath, URL } from 'node:url'
+import {fileURLToPath, URL} from 'node:url'
 import * as path from 'node:path'
-import { defineConfig } from 'vite'
+import {defineConfig} from 'vite'
 import vue from '@vitejs/plugin-vue'
 import vueDevTools from 'vite-plugin-vue-devtools'
+import dotenv from 'dotenv'
+
+
+let envPath = path.resolve(process.cwd(), "vue", '.env')
+if (process.env.VITE_ENV == 'production') {
+   envPath += ".production"
+}
+console.log("> envPath", envPath)
+dotenv.config({path: envPath})
+const routerBase = `${process.env.VITE_ROUTER_BASE}/ui`
+console.log("+ ROUTER BASE IS", routerBase)
 
 // https://vite.dev/config/
 export default defineConfig({
-  base: "/ui",
-  root: path.join(__dirname, 'vue'),
-  plugins: [
-    vue(),
-    vueDevTools(),
-  ],
-  resolve: {
-    alias: {
-      '@': fileURLToPath(new URL('./vue/src', import.meta.url))
-    },
-  },
-  server: {
-    proxy: {
-      '/api': {
-        target: 'http://localhost:4101',
-        changeOrigin: true,
-        // rewrite: (path) => path.replace(/^\/api/, ''),
+   base: routerBase,
+   root: path.join(__dirname, 'vue'),
+   plugins: [
+      vue(),
+      vueDevTools(),
+   ],
+   resolve: {
+      alias: {
+         '@': fileURLToPath(new URL('./vue/src', import.meta.url))
       },
-    },
-  },
+   },
+   server: {
+      proxy: {
+         '/api': {
+            target: 'http://localhost:4101',
+            changeOrigin: true,
+            // rewrite: (path) => path.replace(/^\/api/, ''),
+         },
+      },
+   },
 })
diff --git a/vue/.env.example b/vue/.env.example
new file mode 100644
index 0000000..c4f3e62
--- /dev/null
+++ b/vue/.env.example
@@ -0,0 +1,3 @@
+VITE_API_BASE="/api"
+VITE_ILIAS_BASE="http://localhost:8060"
+VITE_ROUTER_BASE=""
diff --git a/vue/src/App.vue b/vue/src/App.vue
index 6463d3f..a79fcbb 100644
--- a/vue/src/App.vue
+++ b/vue/src/App.vue
@@ -8,7 +8,7 @@
 
 console.log("import.meta.env.VITE_API_BASE",import.meta.env.VITE_API_BASE)
 console.log("import.meta.env.VITE_ILIAS_BASE",import.meta.env.VITE_ILIAS_BASE)
-console.log("import.meta.env.VITE_ROUTER_BASE",import.meta.env.VITE_ILIAS_BASE)
+console.log("import.meta.env.VITE_ROUTER_BASE",import.meta.env.VITE_ROUTER_BASE)
 
 const apiToken = ref("")
 
diff --git a/vue/src/pages/KursDetail.vue b/vue/src/pages/KursDetail.vue
index 0b20326..3ba1df0 100644
--- a/vue/src/pages/KursDetail.vue
+++ b/vue/src/pages/KursDetail.vue
@@ -29,7 +29,6 @@
    console.log(dataKursTn)
    kursTn.value = dataKursTn
 
-   console.log(222222222222,import.meta.env.VITE_TST)
 }
 
 const aaa = import.meta.env.VITE_TST
@@ -39,11 +38,9 @@
 <template>
 
    <div>
-      <pre>---{{aaa}}</pre>
       <h1>
          Kurs
          <small>{{ kurs?.title }}</small>
-         <!--         <small>{{ user?.firstname }} {{ user?.lastname }}</small>-->
       </h1>
       <p v-if="error">{{ error }}</p>
 
diff --git a/vue/src/router.js b/vue/src/router.js
index d7acafe..c8999a0 100644
--- a/vue/src/router.js
+++ b/vue/src/router.js
@@ -8,15 +8,15 @@
 import Kurse from './pages/Kurse.vue'
 import KursDetail from './pages/KursDetail.vue'
 
-const base = import.meta.env.VITE_ROUTER_BASE
 
 const routes = [
-   { path: `${base}/`, redirect: "/user" },
-   { path: `${base}/ui/user`, component: Users },
-   { path: `${base}/ui/user/:userId`, component: UserDetail },
-   { path: `${base}/ui/kurs`, component: Kurse },
-   { path: `${base}/ui/kurs/:kursId`, component: KursDetail },
+   { path: `/`, redirect: "/user" },
+   { path: `/ui/user`, component: Users },
+   { path: `/ui/user/:userId`, component: UserDetail },
+   { path: `/ui/kurs`, component: Kurse },
+   { path: `/ui/kurs/:kursId`, component: KursDetail },
 ]
+console.log(routes)
 
 const router = createRouter({
    history: createWebHistory(),

--
Gitblit v1.8.0