Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/microfrontends/src/bin/local-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,15 @@ export class LocalProxy {
this.proxy = Server.createProxyServer({ secure: true });
this.proxy.on('error', (err, req, res) => {
if (res instanceof http.ServerResponse) {
/** Already closed; nothing left to send. */
if (res.destroyed || res.writableEnded) return;

/** Headers are committed; abort instead of writing a 500. */
if (res.headersSent) {
res.destroy(err);
return;
}

res.writeHead(500, {
'Content-Type': 'text/plain',
});
Expand Down Expand Up @@ -701,6 +710,16 @@ export class LocalProxy {
req.pipe(proxyReq);
proxyReq.on('error', (err) => {
logger.error('Proxy request error: ', err);

/** Already closed; nothing left to send. */
if (res.destroyed || res.writableEnded) return;

/** Headers are committed; abort instead of writing a 500. */
if (res.headersSent) {
res.destroy(err);
return;
}

res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end(
`Error proxying request for ${target.application} to ${hostname}:${port}${path}`,
Expand Down
Loading