Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Speed up the app: serve web UI assets gzipped through the portal (#2331)

Joshua Francedec2b9499dbc
diff --git a/plugins/portal/src/index.ts b/plugins/portal/src/index.ts
index 643a51988..186f0f8b3 100644
--- a/plugins/portal/src/index.ts
+++ b/plugins/portal/src/index.ts
@@ -1288,7 +1288,10 @@ async function handle(req: IncomingMessage, res: ServerResponse): Promise<void>
(/^\/share\/external\/[a-f0-9-]{36}(?:\/files\/[a-f0-9-]{36})?$/.test(pathname) ||
/^\/assets\/[a-zA-Z0-9_.-]+$/.test(pathname))
) {
- return proxyToUpstream(req, res, { baseUrl: UPSTREAMS["web-ui"]!, path: pathname, search: url.search }, ["accept"]);
+ return proxyToUpstream(req, res, { baseUrl: UPSTREAMS["web-ui"]!, path: pathname, search: url.search }, [
+ "accept",
+ "accept-encoding",
+ ]);
}
if (!session) {
diff --git a/plugins/portal/test/session-sharing.test.ts b/plugins/portal/test/session-sharing.test.ts
index 5ad53a610..ceb3d774c 100644
--- a/plugins/portal/test/session-sharing.test.ts
+++ b/plugins/portal/test/session-sharing.test.ts
@@ -3,9 +3,14 @@ import assert from "node:assert/strict";
import { createServer } from "node:http";
import type { AddressInfo } from "node:net";
-const calls: Array<{ url: string; cookie: unknown; identity: unknown }> = [];
+const calls: Array<{ url: string; cookie: unknown; identity: unknown; encoding: unknown }> = [];
const upstream = createServer((req, res) => {
- calls.push({ url: req.url!, cookie: req.headers.cookie, identity: req.headers["x-portal-identity"] });
+ calls.push({
+ url: req.url!,
+ cookie: req.headers.cookie,
+ identity: req.headers["x-portal-identity"],
+ encoding: req.headers["accept-encoding"],
+ });
res.end("public content");
});
await new Promise<void>((resolve) => upstream.listen(0, resolve));
@@ -51,3 +56,9 @@ test("anonymous public shares forward no identity and do not open private routes
assert.equal((await fetch(`${base}/share/external/${token}`, { method: "POST", redirect: "manual" })).status, 401);
assert.equal(calls.length, before);
});
+
+test("app assets pass the browser's accept-encoding through so the prebuilt gzip is served", async () => {
+ await fetch(`${base}/assets/index-Abc123.js`, { headers: { "accept-encoding": "gzip" } });
+ assert.equal(calls.at(-1)!.url, "/assets/index-Abc123.js");
+ assert.match(String(calls.at(-1)!.encoding), /gzip/);
+});