mirror of
https://github.com/morluto/rea.git
synced 2026-11-10 00:36:35 +00:00
refactor(mcp): release the listener through one helper
Replaces a comma expression left by the previous commit with plain statements and moves the port release into a small function, so the listener body stays within the lint limits without changing behaviour. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb22df370b
commit
54a7475602
1 file changed
+15
-7
@@ -297,12 +297,7 @@ export const serveStreamableHttp = async (
|
||||
);
|
||||
const closeListener = async (): Promise<void> => {
|
||||
stopped = true;
|
||||
httpServer.closeAllConnections();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
httpServer.close((error) =>
|
||||
error === undefined ? resolve() : reject(error),
|
||||
);
|
||||
});
|
||||
await closeHttpServer(httpServer);
|
||||
};
|
||||
try {
|
||||
httpServer.listen(port, host);
|
||||
@@ -313,7 +308,8 @@ export const serveStreamableHttp = async (
|
||||
const bound = httpServer.address();
|
||||
let url: string;
|
||||
try {
|
||||
((url = endpointUrl(bound)), (origin = new URL(url).origin));
|
||||
url = endpointUrl(bound);
|
||||
origin = new URL(url).origin;
|
||||
} catch (cause: unknown) {
|
||||
await closeListener().catch(() => undefined);
|
||||
throw new StreamableHttpListenError(cause);
|
||||
@@ -356,6 +352,18 @@ export const serveStreamableHttp = async (
|
||||
return { url, close };
|
||||
};
|
||||
|
||||
/** Drop open connections and release the port. */
|
||||
const closeHttpServer = (
|
||||
httpServer: ReturnType<typeof createHttpServer>,
|
||||
): Promise<void> => {
|
||||
httpServer.closeAllConnections();
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
httpServer.close((error) =>
|
||||
error === undefined ? resolve() : reject(error),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/** Translate one node:http exchange through `route`, logging a failure and answering it when headers are still open. */
|
||||
const serveNodeRequest = async (
|
||||
target: {
|
||||
|
||||
Reference in new issue
Block a user