mirror of
https://github.com/wahyd4/hey-search.git
synced 2026-08-09 05:06:23 +10:00
fix: forward browser Host via Vite proxy for correct API docs URLs
Vite proxy now sends X-Forwarded-Host and X-Forwarded-Proto headers to the backend, so /openapi.json and /docs show the actual browser address (e.g. http://192.168.1.28:5173) instead of localhost:8000. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+19
-4
@@ -3,6 +3,21 @@ import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import path from 'path'
|
||||
|
||||
// Forward browser's original Host to the backend so API docs URLs match
|
||||
function forwardHost() {
|
||||
return {
|
||||
configure: (proxy: any) => {
|
||||
proxy.on('proxyReq', (proxyReq: any, req: any) => {
|
||||
const host = req.headers.host;
|
||||
if (host) {
|
||||
proxyReq.setHeader('X-Forwarded-Host', host);
|
||||
proxyReq.setHeader('X-Forwarded-Proto', 'http');
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
@@ -12,10 +27,10 @@ export default defineConfig({
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': 'http://localhost:8000',
|
||||
'/docs': 'http://localhost:8000',
|
||||
'/redoc': 'http://localhost:8000',
|
||||
'/openapi.json': 'http://localhost:8000',
|
||||
'/api': { target: 'http://localhost:8000', ...forwardHost() },
|
||||
'/docs': { target: 'http://localhost:8000', ...forwardHost() },
|
||||
'/redoc': { target: 'http://localhost:8000', ...forwardHost() },
|
||||
'/openapi.json': { target: 'http://localhost:8000', ...forwardHost() },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user