Update vite to have proper routing for api
This commit is contained in:
parent
02d6ecd28c
commit
4842cef07a
5 changed files with 37 additions and 29 deletions
5
.env
5
.env
|
|
@ -1,2 +1,3 @@
|
|||
VITE_API_URL="http://localhost:8000/api"
|
||||
VITE_APP_URL="http://localhost:5173"
|
||||
VITE_HOST="127.0.0.1"
|
||||
VITE_API_URL="http://$VITE_HOST:8000"
|
||||
VITE_APP_URL="http://$VITE_HOST:5173"
|
||||
|
|
|
|||
16
api/index.py
16
api/index.py
|
|
@ -1,25 +1,13 @@
|
|||
from dotenv import dotenv_values
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from api.db.engine import engine
|
||||
|
||||
config = dotenv_values(".env")
|
||||
|
||||
app = FastAPI()
|
||||
app = FastAPI(root_path="/api")
|
||||
|
||||
|
||||
origins = ["http://localhost", config["VITE_APP_URL"]]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
@app.get("/api/python")
|
||||
@app.get("/v1/python")
|
||||
def hello_world():
|
||||
return {"message": "Hello World"}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const config: PlaywrightTestConfig = {
|
|||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
|
||||
actionTimeout: 0,
|
||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||
baseURL: 'http://localhost:5173',
|
||||
baseURL: 'http://127.0.0.1:5173',
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: 'on-first-retry',
|
||||
|
|
|
|||
|
|
@ -10,5 +10,8 @@
|
|||
{
|
||||
"path": "./tsconfig.vitest.json"
|
||||
}
|
||||
]
|
||||
],
|
||||
"compilerOptions": {
|
||||
"types": ["vite/client"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,26 @@
|
|||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
export default ({ mode }: { mode: string }) => {
|
||||
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
|
||||
|
||||
return defineConfig({
|
||||
server: {
|
||||
host: process.env.VITE_HOST,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.VITE_API_URL,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => {
|
||||
return path.replace(/^\/api/, '');
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
|
|
@ -15,4 +30,5 @@ export default defineConfig({
|
|||
'@': fileURLToPath(new URL('./app', import.meta.url))
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue