The admin and login links pointed at VITE_API_URL (http://localhost:3000) while the app runs at http://127.0.0.1:5173. Browsers keep cookies for the two apart, so logging in there left the app logged out. In development these links now go through Vite's proxy, as GraphQL requests already did. Logging in through the proxy also failed Django's CSRF origin check, because the proxy rewrote the Host header. Keep the app's Host for the local backend; a remote VITE_DEV_API_PROXY still gets its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1005 B
TypeScript
29 lines
1005 B
TypeScript
import { defineConfig } from "vite";
|
|
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
|
|
import babel from "@rolldown/plugin-babel";
|
|
import svgr from "vite-plugin-svgr";
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react(), babel({ presets: [reactCompilerPreset()] }), svgr()],
|
|
define: {
|
|
__DEV__: process.env.NODE_ENV !== "production",
|
|
},
|
|
envDir: "..",
|
|
server: {
|
|
host: "127.0.0.1",
|
|
proxy: Object.fromEntries(
|
|
["/admin", "/accounts", "/static", "/media", "/graphql"].map((path) => [
|
|
path,
|
|
{
|
|
target: process.env.VITE_DEV_API_PROXY || "http://127.0.0.1:3000",
|
|
// Django only accepts a login form posted from the Host it was sent to (CSRF), so keep the
|
|
// app's own Host for the local backend. A remote backend needs its own Host to be reached.
|
|
changeOrigin: !!process.env.VITE_DEV_API_PROXY,
|
|
},
|
|
]),
|
|
),
|
|
},
|
|
build: { outDir: "../static", emptyOutDir: false },
|
|
});
|