Skip to content

Commit

Permalink
Migrating to express 5
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Oct 1, 2024
1 parent 2aba044 commit 6b6f9e5
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 175 deletions.
270 changes: 193 additions & 77 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/ep.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@
"socketio": "ep_etherpad-lite/node/handler/PadMessageHandler"
}
},
{
"name": "tests",
"hooks": {
"expressPreSession": "ep_etherpad-lite/node/hooks/express/tests"
}
},
{
"name": "admin",
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion src/node/hooks/express/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.expressCreateServer = (hookName: string, args: ArgsExpressType, cb: Func
console.error('admin template not found, skipping admin interface. You need to rebuild it in /admin with pnpm run build-copy')
return cb();
}
args.app.get('/admin/*', (req: any, res: any) => {
args.app.get('/admin/:filename', (req: any, res: any) => {
// parse URL
const parsedUrl = url.parse(req.url);
// extract URL path
Expand Down
4 changes: 2 additions & 2 deletions src/node/hooks/express/importexport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
});

// handle export requests
args.app.use('/p/:pad/:rev?/export/:type', limiter);
args.app.get('/p/:pad/:rev?/export/:type', (req:any, res:any, next:Function) => {
args.app.use('/p/:pad/:rev{.:ext}/export/:type', limiter);
args.app.get('/p/:pad/:rev{.:ext}/export/:type', (req:any, res:any, next:Function) => {
(async () => {
const types = ['pdf', 'doc', 'txt', 'html', 'odt', 'etherpad'];
// send a 404 if we don't support this filetype
Expand Down
7 changes: 4 additions & 3 deletions src/node/hooks/express/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {PartType} from "../../types/PartType";
const fs = require('fs').promises;
import {minify} from '../../utils/Minify';
import path from 'node:path';
import {ArgsExpressType} from "../../types/ArgsExpressType";
const plugins = require('../../../static/js/pluginfw/plugin_defs');
const settings = require('../../utils/Settings');

Expand All @@ -30,16 +31,16 @@ const getTar = async () => {
return tar;
};

exports.expressPreSession = async (hookName:string, {app}:any) => {
exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {

// 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.all('/static/*filename', minify);

// serve plugin definitions
// not very static, but served here so that client can do
// require("pluginfw/static/js/plugin-definitions.js");
app.get('/pluginfw/plugin-definitions.json', (req: any, res:any, next:Function) => {
app.get('/pluginfw/plugin-definitions.json', (_req, res) => {
const clientParts = plugins.parts.filter((part: PartType) => part.client_hooks != null);
const clientPlugins:MapArrayType<string> = {};
for (const name of new Set(clientParts.map((part: PartType) => part.plugin))) {
Expand Down
83 changes: 0 additions & 83 deletions src/node/hooks/express/tests.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/node/utils/Minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const compatPaths = {
* @param res the Express response
*/
const _minify = async (req:any, res:any) => {
let filename = req.params.filename;
let filename = req.params.filename.join('/');
try {
filename = sanitizePathname(filename);
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"cross-spawn": "^7.0.3",
"ejs": "^3.1.10",
"esbuild": "^0.24.0",
"express": "4.21.0",
"express": "^5.0.0",
"express-rate-limit": "^7.4.0",
"fast-deep-equal": "^3.1.3",
"find-root": "1.1.0",
Expand Down Expand Up @@ -84,7 +84,7 @@
"devDependencies": {
"@playwright/test": "^1.47.2",
"@types/async": "^3.2.24",
"@types/express": "^4.17.21",
"@types/express": "^5.0.0",
"@types/formidable": "^3.4.5",
"@types/http-errors": "^2.0.4",
"@types/jquery": "^3.5.31",
Expand Down

0 comments on commit 6b6f9e5

Please sign in to comment.