mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
feat: tailscale add host and copy ip, fix outbound fetch hang and plugin ESM warning
This commit is contained in:
1 parent
c21bca8cf0
commit
fbe736bc20
70 files changed
+1117
-1139
No files matched your search
@@ -70,14 +70,14 @@ router.use("/:pluginId", (req: Request, res: Response, next) => {
|
||||
/** 503 for an installed plugin that is off, 404 for an unknown id. */
|
||||
function notServing(res: Response, pluginId: string): void {
|
||||
if (isPluginInstalled(pluginId)) {
|
||||
res.status(503).json({ error: "Plugin is not running", pluginId });
|
||||
res.status(503).json({ error: "This feature is not available", pluginId });
|
||||
return;
|
||||
}
|
||||
databaseLogger.warn("Plugin API request for unregistered plugin", {
|
||||
operation: "plugin_api_dispatch",
|
||||
pluginId,
|
||||
});
|
||||
res.status(404).json({ error: "Plugin not installed" });
|
||||
res.status(404).json({ error: "This feature is not available" });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -175,7 +175,7 @@ export function createPluginRouter({
|
||||
next();
|
||||
return;
|
||||
}
|
||||
res.status(503).json({ error: "Plugin is not running", pluginId });
|
||||
res.status(503).json({ error: "This feature is not available", pluginId });
|
||||
});
|
||||
|
||||
// The grant lives in the database, so it cannot be checked in the
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createServer } from "http";
|
||||
import type { AddressInfo } from "net";
|
||||
import type { LookupAddress, LookupOptions } from "dns";
|
||||
import {
|
||||
createDnsLookupHook,
|
||||
isBlockedAddress,
|
||||
readResponseTextLimited,
|
||||
safeOutboundFetch,
|
||||
} from "../../utils/safe-outbound-fetch.js";
|
||||
|
||||
describe("isBlockedAddress", () => {
|
||||
@@ -257,3 +260,24 @@ describe("createDnsLookupHook", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("safeOutboundFetch", () => {
|
||||
it("returns a large body the caller reads after the call", async () => {
|
||||
const body = "x".repeat(1_000_000);
|
||||
const server = createServer((_req, res) => res.end(body));
|
||||
await new Promise<void>((resolve) =>
|
||||
server.listen(0, "127.0.0.1", resolve),
|
||||
);
|
||||
const { port } = server.address() as AddressInfo;
|
||||
try {
|
||||
const response = await safeOutboundFetch(
|
||||
`http://127.0.0.1:${port}/`,
|
||||
{},
|
||||
["127.0.0.1"],
|
||||
);
|
||||
expect((await response.text()).length).toBe(body.length);
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
}, 10_000);
|
||||
});
|
||||
@@ -237,12 +237,16 @@ export async function safeOutboundFetch(
|
||||
});
|
||||
|
||||
try {
|
||||
return await undiciFetch(url.toString(), {
|
||||
const response = await undiciFetch(url.toString(), {
|
||||
...options,
|
||||
dispatcher,
|
||||
redirect: "error",
|
||||
});
|
||||
} finally {
|
||||
await dispatcher.close();
|
||||
// close() waits for the body, which the caller reads after we return.
|
||||
dispatcher.close().catch(() => {});
|
||||
return response;
|
||||
} catch (error) {
|
||||
await dispatcher.destroy().catch(() => {});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user