Skip to content

Commit

Permalink
Replace compression package with http-compression, because `compr…
Browse files Browse the repository at this point in the history
…ession` does not support HTTP/2

Reference: expressjs/compression#122

Also, separate `response.setHeader` calls from `response.end`, which were causing issues when using HTTPS.
  • Loading branch information
felladrin committed May 18, 2024
1 parent 22580ae commit 58b74a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 221 deletions.
217 changes: 9 additions & 208 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"@mlc-ai/web-llm": "0.2.35",
"@ratchet-ml/ratchet-web": "^0.4.0",
"@wllama/wllama": "^1.4.2",
"compression": "^1.7.4",
"create-pubsub": "^1.6.3",
"hash-wasm": "^4.11.0",
"html-to-text": "^9.0.5",
"http-compression": "^1.0.20",
"inter-ui": "^4.0.2",
"keyword-extractor": "^0.0.28",
"markdown-to-jsx": "^7.3.2",
Expand All @@ -39,7 +39,6 @@
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@types/compression": "^1.7.5",
"@types/html-to-text": "^9.0.4",
"@types/node": "^20.12.7",
"@types/react": "^18.2.15",
Expand Down
22 changes: 11 additions & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@energetic-ai/embeddings";
import { modelSource as embeddingModel } from "@energetic-ai/model-embeddings-en";
import { argon2Verify } from "hash-wasm";
import compression from "compression";
import compression from "http-compression";

const serverStartTime = new Date().getTime();
let searchesSinceLastRestart = 0;
Expand Down Expand Up @@ -116,7 +116,8 @@ function statusEndpointServerHook<T extends ViteDevServer | PreviewServer>(
(new Date().getTime() - serverStartTime) / 1000,
);

response.setHeader("Content-Type", "application/json").end(
response.setHeader("Content-Type", "application/json");
response.end(
JSON.stringify({
secondsSinceLastRestart,
searchesSinceLastRestart,
Expand Down Expand Up @@ -193,21 +194,20 @@ function searchEndpointServerHook<T extends ViteDevServer | PreviewServer>(
searchesSinceLastRestart++;

if (searchResults.length === 0) {
response
.setHeader("Content-Type", "application/json")
.end(JSON.stringify([]));
response.setHeader("Content-Type", "application/json");
response.end(JSON.stringify([]));
return;
}

try {
response
.setHeader("Content-Type", "application/json")
.end(JSON.stringify(await rankSearchResults(query, searchResults)));
response.setHeader("Content-Type", "application/json");
response.end(
JSON.stringify(await rankSearchResults(query, searchResults)),
);
} catch (error) {
console.error("Error ranking search results:", error);
response
.setHeader("Content-Type", "application/json")
.end(JSON.stringify(searchResults));
response.setHeader("Content-Type", "application/json");
response.end(JSON.stringify(searchResults));
}
});
}
Expand Down

0 comments on commit 58b74a4

Please sign in to comment.