fix(server): gestion erreur WebSocket au build + rewrite URL protocol-relative dans le proxy
- api/websocket: capture asynchrone EADDRINUSE pour ne pas bloquer le build - proxy: réécrit aussi les URLs protocol-relatives (//localhost) dans le corps
This commit is contained in:
@@ -111,7 +111,8 @@ async function proxyRequest(req: NextRequest) {
|
||||
});
|
||||
}
|
||||
|
||||
// For text responses, rewrite localhost/internal URLs to the public URL
|
||||
// For text responses, rewrite localhost/internal URLs to the public URL.
|
||||
// Also handle protocol-relative URLs that some WordPress plugins/themes use.
|
||||
let body = await upstreamRes.text();
|
||||
const localBase = `http://${instance.node.tailscaleIp}:${instance.port}`;
|
||||
const localBaseHttps = `https://${instance.node.tailscaleIp}:${instance.port}`;
|
||||
@@ -119,6 +120,8 @@ async function proxyRequest(req: NextRequest) {
|
||||
const localLocalhostHttps = `https://localhost:${instance.port}`;
|
||||
const localLocalhostPlainHttp = `http://localhost`;
|
||||
const localLocalhostPlainHttps = `https://localhost`;
|
||||
const localLocalhostProtocolRelative = `//localhost`;
|
||||
const localTailscaleProtocolRelative = `//${instance.node.tailscaleIp}:${instance.port}`;
|
||||
|
||||
body = body
|
||||
.replaceAll(localBase, publicUrl)
|
||||
@@ -126,7 +129,9 @@ async function proxyRequest(req: NextRequest) {
|
||||
.replaceAll(localLocalhostHttp, publicUrl)
|
||||
.replaceAll(localLocalhostHttps, publicUrl)
|
||||
.replaceAll(localLocalhostPlainHttp, publicUrl)
|
||||
.replaceAll(localLocalhostPlainHttps, publicUrl);
|
||||
.replaceAll(localLocalhostPlainHttps, publicUrl)
|
||||
.replaceAll(localTailscaleProtocolRelative, publicUrl.replace(/^https?:/, ""))
|
||||
.replaceAll(localLocalhostProtocolRelative, publicUrl.replace(/^https?:/, ""));
|
||||
|
||||
return new Response(body, {
|
||||
status: upstreamRes.status,
|
||||
|
||||
Reference in New Issue
Block a user