From 3c66e8c5d67335b9c5e27a47152fe985045a4b8a Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Sun, 18 Aug 2024 22:29:19 +0200 Subject: [PATCH] Added nanoexpress --- pnpm-lock.yaml | 45 ++++++++++++++++++++++++ src/node/hooks/express.ts | 3 +- src/node/hooks/express/padurlsanitize.ts | 4 +-- src/node/hooks/express/static.ts | 2 +- src/package.json | 1 + 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5e4f96ae..d98f4c8ba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -218,6 +218,9 @@ importers: mime-types: specifier: ^2.1.35 version: 2.1.35 + nanoexpress: + specifier: ^6.4.4 + version: 6.4.4 oidc-provider: specifier: ^8.5.1 version: 8.5.1 @@ -549,6 +552,12 @@ packages: resolution: {integrity: sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==} engines: {node: '>=6.9.0'} + '@dalisoft/args@0.1.1': + resolution: {integrity: sha512-PwmLEhnTyK6+AUwD0oqS57nLs1vpB17vEDlMc1i27zH8mrtFJmBmYfQv4FszoUHDHv3PtFk8M0X9yWxry2TSwA==} + + '@dalisoft/events@0.2.0': + resolution: {integrity: sha512-2NS/0vS9eL8ZxhgCVZQgPS4uoqbcSk9FN3G8Eqakcej7wOpH72z1kmDEDGI5T+MOp9IueKT2qI0XUdXhKeK9GA==} + '@docsearch/css@3.6.0': resolution: {integrity: sha512-+sbxb71sWre+PwDK7X2T8+bhS6clcVMLwBPznX45Qu6opJcgRjAp7gYSDzVFp187J+feSj5dNBN1mJoi6ckkUQ==} @@ -2646,6 +2655,9 @@ packages: extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} + fast-decode-uri-component@1.0.1: + resolution: {integrity: sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==} + fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -2659,6 +2671,9 @@ packages: fast-levenshtein@2.0.6: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} + fast-query-parse@3.0.0: + resolution: {integrity: sha512-u4vMOOKVZalfh0JygVJQLE1POZrgdKtptmNHt6CVRCVSClNIP7T1yjI/EyT+YlVJTb1PsnVWKMjDzbsTRtPm6Q==} + fast-safe-stringify@2.1.1: resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} @@ -3505,6 +3520,10 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + nanoexpress@6.4.4: + resolution: {integrity: sha512-yyGHOl9koJf7C/a6Ojs6boKaZyrTneCG76vL+/SqDC1uRn9f/h6LL84PbVT22rX1SVQ5NB8v7mfoRrjbUPWpyQ==} + engines: {node: '>=18.20.4'} + nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -4306,6 +4325,10 @@ packages: engines: {node: '>=14.17'} hasBin: true + uWebSockets.js@https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/6f4b450fc642abba540535f0755c990b42a16026: + resolution: {tarball: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/6f4b450fc642abba540535f0755c990b42a16026} + version: 20.47.0 + ueberdb2@4.2.93: resolution: {integrity: sha512-inWXazVuEJc33aRBm6kCT8/ymgSvHcXbakKf4nxVf8Wp86Le0cQd3URn3cCUhxRV05qP14kDdvAQho9LUiXWwg==} engines: {node: '>=16.20.1'} @@ -4927,6 +4950,12 @@ snapshots: '@babel/helper-validator-identifier': 7.24.7 to-fast-properties: 2.0.0 + '@dalisoft/args@0.1.1': {} + + '@dalisoft/events@0.2.0': + dependencies: + '@dalisoft/args': 0.1.1 + '@docsearch/css@3.6.0': {} '@docsearch/js@3.6.0(@algolia/client-search@4.23.3)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': @@ -7137,6 +7166,8 @@ snapshots: extend@3.0.2: {} + fast-decode-uri-component@1.0.1: {} + fast-deep-equal@3.1.3: {} fast-glob@3.3.2: @@ -7151,6 +7182,10 @@ snapshots: fast-levenshtein@2.0.6: {} + fast-query-parse@3.0.0: + dependencies: + fast-decode-uri-component: 1.0.1 + fast-safe-stringify@2.1.1: {} fast-uri@3.0.1: {} @@ -8102,6 +8137,14 @@ snapshots: ms@2.1.3: {} + nanoexpress@6.4.4: + dependencies: + '@dalisoft/events': 0.2.0 + ajv: 8.17.1 + cookie: 0.6.0 + fast-query-parse: 3.0.0 + uWebSockets.js: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/6f4b450fc642abba540535f0755c990b42a16026 + nanoid@3.3.7: {} nanoid@5.0.7: {} @@ -9009,6 +9052,8 @@ snapshots: typescript@5.5.4: {} + uWebSockets.js@https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/6f4b450fc642abba540535f0755c990b42a16026: {} + ueberdb2@4.2.93: {} uid-safe@2.1.5: diff --git a/src/node/hooks/express.ts b/src/node/hooks/express.ts index d4e92dd35..9a714e17f 100644 --- a/src/node/hooks/express.ts +++ b/src/node/hooks/express.ts @@ -18,6 +18,7 @@ const settings = require('../utils/Settings'); const stats = require('../stats') import util from 'util'; const webaccess = require('./express/webaccess'); +import nanoexpress from 'nanoexpress'; import SecretRotator from '../security/SecretRotator'; @@ -100,7 +101,7 @@ exports.createServer = async () => { exports.restartServer = async () => { await closeServer(); - const app = express(); // New syntax for express v3 + const app = nanoexpress(); // New syntax for express v3 if (settings.ssl) { console.log('SSL -- enabled'); diff --git a/src/node/hooks/express/padurlsanitize.ts b/src/node/hooks/express/padurlsanitize.ts index 8679bcfe3..d4aa27c97 100644 --- a/src/node/hooks/express/padurlsanitize.ts +++ b/src/node/hooks/express/padurlsanitize.ts @@ -6,7 +6,7 @@ const padManager = require('../../db/PadManager'); exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Function) => { // redirects browser to the pad's sanitized url if needed. otherwise, renders the html - args.app.param('pad', (req:any, res:any, next:Function, padId:string) => { + /*args.app.param('pad', (req:any, res:any, next:Function, padId:string) => { (async () => { // ensure the padname is valid and the url doesn't end with a / if (!padManager.isValidPadId(padId) || /\/$/.test(req.url)) { @@ -27,6 +27,6 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio res.status(302).send(`You should be redirected to ${realURL}`); } })().catch((err) => next(err || new Error(err))); - }); + });*/ return cb(); }; diff --git a/src/node/hooks/express/static.ts b/src/node/hooks/express/static.ts index 07a7f3a21..3cb8caa8d 100644 --- a/src/node/hooks/express/static.ts +++ b/src/node/hooks/express/static.ts @@ -34,7 +34,7 @@ exports.expressPreSession = async (hookName:string, {app}:any) => { // Minify will serve static files compressed (minify enabled). It also has // file-specific hacks for ace/require-kernel/etc. - app.all('/static/:filename(*)', minify); + app.get('/static/:filename(*)', minify); // serve plugin definitions // not very static, but served here so that client can do diff --git a/src/package.json b/src/package.json index 80031af7a..8d8717246 100644 --- a/src/package.json +++ b/src/package.json @@ -56,6 +56,7 @@ "lru-cache": "^11.0.0", "measured-core": "^2.0.0", "mime-types": "^2.1.35", + "nanoexpress": "^6.4.4", "oidc-provider": "^8.5.1", "openapi-backend": "^5.10.6", "proxy-addr": "^2.0.7",