lollms-webui/web/vite.config.mjs

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-05-02 20:53:27 +00:00
import { fileURLToPath, URL } from 'node:url'
2023-05-03 21:00:07 +00:00
import { defineConfig,loadEnv } from 'vite'
2023-05-02 20:53:27 +00:00
import vue from '@vitejs/plugin-vue'
2023-11-09 01:00:49 +00:00
2023-05-02 20:53:27 +00:00
// https://vitejs.dev/config/
2023-11-09 01:00:49 +00:00
export default async ({ mode }) => {
2023-11-26 18:54:09 +00:00
/*
2023-11-09 01:00:49 +00:00
async function getFlaskServerURL() {
try {
2023-11-21 22:50:17 +00:00
console.log("Loading")
2023-11-09 01:00:49 +00:00
const response = await fetch('/get_server_address'); // Replace with the actual endpoint on your Flask server
const serverAddress = await response.text();
2023-11-19 00:21:29 +00:00
if(serverAddress.includes('<') || !serverAddress.startsWith("http")){
2023-11-11 21:21:40 +00:00
console.log(`Server address not found`)
return process.env.VITE_LOLLMS_API
2023-11-12 01:20:53 +00:00
2023-11-11 21:21:40 +00:00
}
2023-11-09 01:00:49 +00:00
console.log(`Server address: ${serverAddress}`)
return `${serverAddress}`; // Construct the full server address dynamically
} catch (error) {
// console.error('Error fetching server address:', error);
// Handle error if necessary
return process.env.VITE_LOLLMS_API
}
}
2023-11-22 19:35:48 +00:00
let serverURL = undefined;
try{
serverURL = await getFlaskServerURL()
console.log(serverURL)
}catch{
serverURL = process.env.VITE_LOLLMS_API
console.log(`Server address: ${serverAddress}`)
}
2023-11-26 18:54:09 +00:00
*/
2023-05-03 21:00:07 +00:00
// Load app-level env vars to node-level env vars.
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
return defineConfig({
2023-07-13 23:42:29 +00:00
2023-05-02 20:53:27 +00:00
plugins: [
vue()
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
"/api/": {
2023-11-26 18:54:09 +00:00
target: process.env.VITE_LOLLMS_API,//serverURL,
2023-07-16 16:57:30 +00:00
changeOrigin: process.env.VITE_LOLLMS_API_CHANGE_ORIGIN,
secure: process.env.VITE_LOLLMS_API_SECURE,
2023-05-02 20:53:27 +00:00
rewrite: (path) => path.replace(/^\/api/, ""),
},
2023-07-01 13:57:59 +00:00
// "/": {
2023-07-16 16:57:30 +00:00
// target: process.env.VITE_LOLLMS_API,
// changeOrigin: process.env.VITE_LOLLMS_API_CHANGE_ORIGIN,
// secure: process.env.VITE_LOLLMS_API_SECURE,
2023-07-01 11:47:03 +00:00
2023-07-01 13:57:59 +00:00
// },
2023-07-01 11:47:03 +00:00
2023-05-02 20:53:27 +00:00
},
2023-05-03 21:00:07 +00:00
}
})}