Update scripts with latest fastapi-vue-setup.

This commit is contained in:
2026-01-30 18:40:26 +00:00
parent 7be02e951d
commit 849b1a6868
11 changed files with 467 additions and 306 deletions
+35
View File
@@ -0,0 +1,35 @@
/**
* FastAPI-Vue Vite Plugin
*
* Configures Vite for FastAPI backend integration:
* - Proxies /api/* requests to the FastAPI backend
* - Builds to the Python module's frontend-build directory
*
* Environment variables (with defaults):
* FASTAPI_VUE_BACKEND_URL=http://localhost:5180 - Backend API URL for proxying
*/
const backendUrl = process.env.FASTAPI_VUE_BACKEND_URL || "http://localhost:5180"
export default function fastapiVue({ paths = ["/api"] } = {}) {
// Build proxy configuration for each path
const proxy = {}
for (const path of paths) {
proxy[path] = {
target: backendUrl,
changeOrigin: false,
ws: true,
}
}
return {
name: "fastapi-vite",
config: () => ({
server: { proxy },
build: {
outDir: "../cista/frontend-build",
emptyOutDir: true,
},
}),
}
}
+3 -19
View File
@@ -1,4 +1,5 @@
import { fileURLToPath, URL } from 'node:url'
import fastapiVue from './vite-plugin-fastapi.js'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
@@ -7,15 +8,11 @@ import vue from '@vitejs/plugin-vue'
import svgLoader from 'vite-svg-loader'
import Components from 'unplugin-vue-components/vite'
const dev_backend = {
target: process.env.CISTA_BACKEND_URL || "http://localhost:8989",
changeOrigin: false, // Use frontend "host" to match "origin" from browser
ws: true,
}
// https://vitejs.dev/config/
// Note: fastapiVue() handles proxy and build output (uses FASTAPI_VUE_BACKEND_URL env)
export default defineConfig({
plugins: [
fastapiVue({ paths: ["/api", "/auth", "/files", "/zip", "/preview"] }),
vue(),
svgLoader(), // import svg files
Components(), // auto import components
@@ -33,17 +30,4 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
"/api": dev_backend,
"/auth": dev_backend,
"/files": dev_backend,
"/zip": dev_backend,
"/preview": dev_backend,
}
},
build: {
outDir: "../cista/frontend-build",
emptyOutDir: true,
}
})