mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
Use a dynamic port for the test-http-api to avoid conflicts
Pick a free port at config load time using a TCP probe on port 0, inject it into the Vite dev server via VITE_TEST_HTTP_API_PORT, and have globalSetup start the test-http-api on the same port. The frontend reads the env var at build time instead of the previously hardcoded 8081.
This commit is contained in:
+8
-5
@@ -49,11 +49,14 @@ async function withTestBackend<T>(
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return fetch(`http://127.0.0.1:8081/${cmd}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(args),
|
||||
}).then(async response => {
|
||||
return fetch(
|
||||
`http://127.0.0.1:${import.meta.env.VITE_TEST_HTTP_API_PORT ?? 8081}/${cmd}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(args),
|
||||
},
|
||||
).then(async response => {
|
||||
if (response.status === 404) {
|
||||
console.log("Got a 404 response:", response);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user