Skip to content

Revert "deps: manual upgrade to express 5.1.0" #1681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025

Conversation

eliandoran
Copy link
Contributor

@eliandoran eliandoran commented Apr 11, 2025

Reverts #1626

image

It appears that the Electron build uses an interesting system in which the requests from the client to the server and intercepted in order not to be served over HTTP (for performance reasons).

Unfortunately, this PR breaks the Electron run entirely, most likely due to the API change of Express 5.

Was almost able to solve it on my side, but I couldn't get past the CLS event handler thing. So that only leaves me with reverting it for the time being.

Note that I had to bump the version of @types/express-serve-static-core due to the fact that it had the incorrect data type for the router (which is now public according to the changelog, instead of private as it used to be).

This also highlights a significant issue regarding our process. We should have some systems in place that fail if the Electron build fails to run at all.

diff --git a/package-lock.json b/package-lock.json
index 4fa6f1d5d..909fc5f66 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
         "@electron/remote": "2.1.2",
         "@highlightjs/cdn-assets": "11.11.1",
         "@triliumnext/express-partial-content": "1.1.0",
+        "@types/express-serve-static-core": "5.0.6",
         "archiver": "7.0.1",
         "async-mutex": "0.5.0",
         "autocomplete.js": "0.38.1",
@@ -5018,10 +5019,9 @@
       }
     },
     "node_modules/@types/express-serve-static-core": {
-      "version": "5.0.2",
-      "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.0.2.tgz",
-      "integrity": "sha512-vluaspfvWEtE4vcSDlKRNer52DvOGrB2xv6diXy6UKyKW0lqZiWHGNApSyxOv+8DE5Z27IzVvE7hNkxg7EXIcg==",
-      "dev": true,
+      "version": "5.0.6",
+      "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.0.6.tgz",
+      "integrity": "sha512-3xhRnjJPkULekpSzgtoNYYcTWgEZkp4myc+Saevii5JPnHNvHMRlBSHDbs7Bh1iPPoVTERHEZXyhyLbMEsExsA==",
       "license": "MIT",
       "dependencies": {
         "@types/node": "*",
@@ -5235,7 +5235,6 @@
       "version": "1.3.5",
       "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",
       "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==",
-      "dev": true,
       "license": "MIT"
     },
     "node_modules/@types/mime-types": {
@@ -5290,14 +5289,12 @@
       "version": "6.9.17",
       "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.17.tgz",
       "integrity": "sha512-rX4/bPcfmvxHDv0XjfJELTTr+iB+tn032nPILqHm5wbthUUUuVtNGGqzhya9XUxjTP8Fpr0qYgSZZKxGY++svQ==",
-      "dev": true,
       "license": "MIT"
     },
     "node_modules/@types/range-parser": {
       "version": "1.2.7",
       "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz",
       "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==",
-      "dev": true,
       "license": "MIT"
     },
     "node_modules/@types/react": {
@@ -5371,7 +5368,6 @@
       "version": "0.17.4",
       "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz",
       "integrity": "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==",
-      "dev": true,
       "license": "MIT",
       "dependencies": {
         "@types/mime": "^1",
diff --git a/package.json b/package.json
index 53ac1081e..40f1ab93c 100644
--- a/package.json
+++ b/package.json
@@ -75,6 +75,7 @@
     "@electron/remote": "2.1.2",
     "@highlightjs/cdn-assets": "11.11.1",
     "@triliumnext/express-partial-content": "1.1.0",
+    "@types/express-serve-static-core": "5.0.6",
     "archiver": "7.0.1",
     "async-mutex": "0.5.0",
     "autocomplete.js": "0.38.1",
diff --git a/src/routes/electron.ts b/src/routes/electron.ts
index 05e21e77b..65810bad8 100644
--- a/src/routes/electron.ts
+++ b/src/routes/electron.ts
@@ -7,7 +7,9 @@ interface Response {
     setHeader: (name: string, value: string) => Response;
     header: (name: string, value: string) => Response;
     status: (statusCode: number) => Response;
+    locals: Record<string, unknown>;
     send: (obj: {}) => void; // eslint-disable-line @typescript-eslint/no-empty-object-type
+    json: (obj: {}) => void; // eslint-disable-line @typescript-eslint/no-empty-object-type
 }
 
 function init(app: Application) {
@@ -39,7 +41,9 @@ function init(app: Application) {
                 res.statusCode = statusCode;
                 return res;
             },
+            locals: {},
             send: (obj) => {
+                console.log("Sending response ", obj);
                 event.sender.send("server-response", {
                     url: arg.url,
                     method: arg.method,
@@ -48,10 +52,13 @@ function init(app: Application) {
                     headers: respHeaders,
                     body: obj
                 });
+            },
+            json: (obj) => {
+                res.send(JSON.stringify(obj));
             }
         };
 
-        return app._router.handle(req, res, () => {});
+        return app.router(req, res, () => {});
     });
 }
 
diff --git a/src/routes/routes.ts b/src/routes/routes.ts
index cd49f5a6e..9d8d93b23 100644
--- a/src/routes/routes.ts
+++ b/src/routes/routes.ts
@@ -470,6 +470,7 @@ function route(method: HttpMethod, path: string, middleware: express.Handler[],
         const start = Date.now();
 
         try {
+            console.log("Trying to bind", req, res);
             cls.namespace.bindEmitter(req);
             cls.namespace.bindEmitter(res);

Copy link

Folder/File Previous size New size Difference
/upload/TriliumNextNotes-Server-1681-merge-linux-x64.tar.xz 87.18MB +87.18MB (+100.00%)
TOTAL +87.18MB

Copy link

Folder/File Previous size New size Difference
/upload/TriliumNextNotes-1681-merge-linux-x64.deb 139.79MB +139.79MB (+100.00%)
/upload/TriliumNextNotes-1681-merge-linux-x64.flatpak 132.77MB +132.77MB (+100.00%)
/upload/TriliumNextNotes-1681-merge-linux-x64.rpm 147.71MB +147.71MB (+100.00%)
/upload/TriliumNextNotes-1681-merge-linux-x64.zip 178.85MB +178.85MB (+100.00%)
TOTAL +599.11MB

@eliandoran eliandoran marked this pull request as ready for review April 11, 2025 14:03
@eliandoran eliandoran merged commit 0ddc126 into develop Apr 11, 2025
10 checks passed
@eliandoran eliandoran deleted the revert-1626-deps_express5 branch April 11, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant