Vite proxy: use VITE_API_URL from .env, forward Host/Proto for NIP-98
Made-with: Cursor
This commit is contained in:
@@ -1,37 +1,58 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
sourcemap: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
vendor: ["react", "react-dom", "react-router-dom"],
|
||||
nostr: ["nostr-tools"],
|
||||
ui: ["framer-motion", "qrcode", "canvas-confetti"],
|
||||
/** Proxy config that forwards client Host/Proto so NIP-98 URL validation matches. */
|
||||
function proxyToBackendWithForwarded(backendTarget: string) {
|
||||
return {
|
||||
target: backendTarget,
|
||||
changeOrigin: true,
|
||||
configure: (proxy) => {
|
||||
proxy.on("proxyReq", (proxyReq, req) => {
|
||||
const host = (req.headers.host as string) || "";
|
||||
const proto = (req.headers["x-forwarded-proto"] as string) || "http";
|
||||
proxyReq.setHeader("X-Forwarded-Host", host);
|
||||
proxyReq.setHeader("X-Forwarded-Proto", proto);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), "");
|
||||
const backendTarget = env.VITE_API_URL || "http://localhost:3001";
|
||||
|
||||
return {
|
||||
plugins: [react()],
|
||||
build: {
|
||||
sourcemap: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
vendor: ["react", "react-dom", "react-router-dom"],
|
||||
nostr: ["nostr-tools"],
|
||||
ui: ["framer-motion", "qrcode", "canvas-confetti"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
allowedHosts: ["faucet.lnpulse.app"],
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:3001",
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||
},
|
||||
"/claim": { target: "http://localhost:3001", changeOrigin: true },
|
||||
"/auth": { target: "http://localhost:3001", changeOrigin: true },
|
||||
"/user": { target: "http://localhost:3001", changeOrigin: true },
|
||||
"/config": { target: "http://localhost:3001", changeOrigin: true },
|
||||
"/stats": { target: "http://localhost:3001", changeOrigin: true },
|
||||
"/deposit": { target: "http://localhost:3001", changeOrigin: true },
|
||||
preview: {
|
||||
allowedHosts: ["faucet.lnpulse.app"],
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: backendTarget,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||
},
|
||||
"/claim": proxyToBackendWithForwarded(backendTarget),
|
||||
"/auth": proxyToBackendWithForwarded(backendTarget),
|
||||
"/user": proxyToBackendWithForwarded(backendTarget),
|
||||
"/config": { target: backendTarget, changeOrigin: true },
|
||||
"/stats": { target: backendTarget, changeOrigin: true },
|
||||
"/deposit": { target: backendTarget, changeOrigin: true },
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user