fix(dev): proxy api during react development
This commit is contained in:
parent
b1d196e4ca
commit
b8e39348e8
11 changed files with 196 additions and 8 deletions
|
|
@ -2,6 +2,23 @@ import { fileURLToPath } from "node:url";
|
|||
import tailwindcss from "@tailwindcss/vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { defineConfig, configDefaults } from "vitest/config";
|
||||
import type { UserConfig } from "vite";
|
||||
|
||||
export function createDevServerConfig(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): UserConfig["server"] {
|
||||
const apiTarget = env.DASHBOARD_DEV_API_TARGET;
|
||||
if (!apiTarget) return undefined;
|
||||
|
||||
return {
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: apiTarget,
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
|
|
@ -10,6 +27,7 @@ export default defineConfig({
|
|||
$lib: fileURLToPath(new URL("./src/lib", import.meta.url)),
|
||||
},
|
||||
},
|
||||
server: createDevServerConfig(),
|
||||
test: {
|
||||
exclude: [...configDefaults.exclude, "tests/e2e/**"],
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue