Fix LAN API access and dev proxy routing

This commit is contained in:
2026-03-01 14:08:48 -03:00
parent 48cfc79b5f
commit 3d280396ae
6 changed files with 15 additions and 13 deletions

View File

@@ -97,11 +97,11 @@ async function runApiTests(): Promise<void> {
assert(await thumbnail.text() === 'preview-bytes', 'Thumbnail blob bytes mismatch');
assert(await preview.text() === 'preview-bytes', 'Preview blob bytes mismatch');
assert(
requestUrls[0] === 'http://localhost:8000/api/v1/documents/doc-1/thumbnail',
requestUrls[0] === '/api/v1/documents/doc-1/thumbnail',
`Unexpected thumbnail URL ${requestUrls[0]}`,
);
assert(
requestUrls[1] === 'http://localhost:8000/api/v1/documents/doc-1/preview',
requestUrls[1] === '/api/v1/documents/doc-1/preview',
`Unexpected preview URL ${requestUrls[1]}`,
);
assert(requestAuthHeaders[0] === null, `Expected no auth header for thumbnail request, got "${requestAuthHeaders[0]}"`);

View File

@@ -14,7 +14,7 @@ import type {
} from '../types';
/**
* Resolves backend base URL from environment with current-host HTTP fallback.
* Resolves backend base URL from environment with same-origin proxy fallback.
*/
function resolveApiBase(): string {
const envValue = import.meta.env?.VITE_API_BASE;
@@ -25,11 +25,7 @@ function resolveApiBase(): string {
}
}
if (typeof window !== 'undefined' && window.location?.hostname) {
return `http://${window.location.hostname}:8000/api/v1`;
}
return 'http://localhost:8000/api/v1';
return '/api/v1';
}
const API_BASE = resolveApiBase();

View File

@@ -10,5 +10,11 @@ export default defineConfig({
server: {
host: '0.0.0.0',
port: 5173,
proxy: {
'/api/v1': {
target: process.env.VITE_DEV_PROXY_TARGET ?? 'http://localhost:8000',
changeOrigin: true,
},
},
},
});