Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
826dc93
Fixed determining file extension.
SamTV12345 Jan 20, 2024
1a8e5b1
Added ts-node
SamTV12345 Jan 20, 2024
1893cef
Fixed backend tests.
SamTV12345 Jan 20, 2024
ac5c65b
Fixed frontend test runs.
SamTV12345 Jan 20, 2024
fadc56e
Fixed tests.
SamTV12345 Jan 20, 2024
cfaee1a
Use script approach for starting etherpad.
SamTV12345 Jan 20, 2024
c4fa093
Change directory to src.
SamTV12345 Jan 20, 2024
e154a61
Fixed env.
SamTV12345 Jan 20, 2024
71cd42d
Change directory
SamTV12345 Jan 20, 2024
3d7ca0f
Fixed build arg.
SamTV12345 Jan 20, 2024
cb97af3
Fixed docker build.
SamTV12345 Jan 20, 2024
cf62973
Fixed.
SamTV12345 Jan 20, 2024
ef650be
Fixed cypress file path.
SamTV12345 Jan 20, 2024
996fcab
Fixed.
SamTV12345 Jan 20, 2024
df9ba59
Use latest node container.
SamTV12345 Jan 20, 2024
9842a03
Fixed windows workflow.
SamTV12345 Jan 20, 2024
c10867c
Use tsx and optimized docker image.
SamTV12345 Jan 21, 2024
2d69099
Added workflow for type checks.
SamTV12345 Jan 21, 2024
dedb7c7
Fixed.
SamTV12345 Jan 21, 2024
93dffc0
Added tsconfig.
SamTV12345 Jan 21, 2024
c24ae14
Converted more files to typescript.
SamTV12345 Jan 21, 2024
1009b02
Removed commented keys.
SamTV12345 Jan 21, 2024
cd98696
Typed caching middleware.
SamTV12345 Jan 22, 2024
d5c011e
Added script for checking the types.
SamTV12345 Jan 23, 2024
a57b13d
Moved SecretRotator to typescript.
SamTV12345 Jan 24, 2024
d2cbe1b
Fixed npm installation and moved to types folder.
SamTV12345 Jan 24, 2024
e521b4b
Use better scripts for watching typescript changes.
SamTV12345 Jan 24, 2024
1252b0d
Update windows.yml
SamTV12345 Jan 24, 2024
2df3011
Fixed order of npm installation.
SamTV12345 Jan 24, 2024
545c7c6
Converted i18n.
SamTV12345 Jan 24, 2024
03e7305
Added more types.
SamTV12345 Jan 24, 2024
6fdf9ed
Added more types.
SamTV12345 Jan 30, 2024
b617ac4
Fixed import.
SamTV12345 Jan 30, 2024
1f43bf5
Fixed tests.
SamTV12345 Feb 5, 2024
dfef1e7
Fixed tests.
SamTV12345 Feb 5, 2024
04b88cf
Fixed type checking test.
SamTV12345 Feb 5, 2024
85881c7
Fixed stats
SamTV12345 Feb 5, 2024
f604eb8
Added express types.
SamTV12345 Feb 5, 2024
8519119
fixed.
SamTV12345 Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/perform-type-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Perform type checks"

# any branch is useful for testing before a PR is submitted
on: [push, pull_request]

permissions:
contents: read


jobs:
performTypeCheck:
if: |
(github.event_name != 'pull_request')
|| (github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id)
name: perform type check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: |
src/package-lock.json
src/bin/doc/package-lock.json
-
name: Install all dependencies and symlink for ep_etherpad-lite
run: ./bin/installDeps.sh
working-directory: ./src
- name: Perform type check
working-directory: ./src
run: npm run ts-check
2 changes: 1 addition & 1 deletion .github/workflows/rate-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
-
name: build docker image
run: |
docker build -f Dockerfile -t epl-debian-slim .
docker build -f Dockerfile -t epl-debian-slim --build-arg NODE_ENV=develop .
docker build -f src/tests/ratelimit/Dockerfile.nginx -t nginx-latest .
docker build -f src/tests/ratelimit/Dockerfile.anotherip -t anotherip .
-
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/upgrade-from-latest-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ jobs:
run: src/bin/installDeps.sh
-
name: Run the backend tests
run: cd src && npm test
working-directory: ./src
run: npm test
-
name: Install Cypress
run: cd src && npm install cypress --legacy-peer-deps
working-directory: ./src
run: npm install cypress --legacy-peer-deps
-
name: Run Etherpad & Test Frontend
working-directory: ./src
run: |
node src/node/server.js &
npm run dev &
curl --connect-timeout 10 --max-time 20 --retry 5 --retry-delay 10 --retry-max-time 60 --retry-connrefused http://127.0.0.1:9001/p/test
./src/node_modules/cypress/bin/cypress run --config-file src/tests/frontend/cypress/cypress.config.js
./node_modules/cypress/bin/cypress run --config-file tests/frontend/cypress/cypress.config.js
6 changes: 4 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ jobs:
cache-dependency-path: |
etherpad/src/package-lock.json
etherpad/src/bin/doc/package-lock.json
- name: Install npm@6
run: npm install npm@6 -g
-
name: Install Cypress
run: cd etherpad && cd src && npm install cypress --legacy-peer-deps
run: cd etherpad && npm install cypress --legacy-peer-deps
-
name: Run Etherpad
run: |
cd etherpad
node node_modules\ep_etherpad-lite\node\server.js &
npm run prod --prefix ./src
curl --connect-timeout 10 --max-time 20 --retry 5 --retry-delay 10 --retry-max-time 60 --retry-connrefused http://127.0.0.1:9001/p/test
src\node_modules\cypress\bin\cypress run --config-file src\tests\frontendcypress\cypress.config.js
# On release, upload windows zip to GitHub release tab
Expand Down
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Author: muxator

FROM node:lts-alpine
FROM node:alpine AS builder
LABEL maintainer="Etherpad team, https://github.com/ether/etherpad-lite"

ARG TIMEZONE=
Expand Down Expand Up @@ -63,7 +63,8 @@ ARG EP_UID=5001
ARG EP_GID=0
ARG EP_SHELL=

ENV NODE_ENV=production
ARG NODE_ENV
ENV NODE_ENV=${NODE_ENV:-production}

RUN groupadd --system ${EP_GID:+--gid "${EP_GID}" --non-unique} etherpad && \
useradd --system ${EP_UID:+--uid "${EP_UID}" --non-unique} --gid etherpad \
Expand All @@ -73,6 +74,7 @@ RUN groupadd --system ${EP_GID:+--gid "${EP_GID}" --non-unique} etherpad && \
ARG EP_DIR=/opt/etherpad-lite
RUN mkdir -p "${EP_DIR}" && chown etherpad:etherpad "${EP_DIR}"

USER root
# the mkdir is needed for configuration of openjdk-11-jre-headless, see
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199
RUN \
Expand Down Expand Up @@ -108,13 +110,16 @@ RUN { [ -z "${ETHERPAD_PLUGINS}" ] || \
COPY --chown=etherpad:etherpad ${SETTINGS} "${EP_DIR}"/settings.json

# Fix group permissions
RUN chmod -R g=u .
#RUN chmod -R g=u .

USER root
RUN cd src && npm link

USER etherpad

WORKDIR /opt/etherpad-lite

HEALTHCHECK --interval=20s --timeout=3s CMD ["etherpad-healthcheck"]

EXPOSE 9001
CMD ["etherpad"]
CMD ["npm", "run", "prod", "--prefix", "./src"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Update to the latest version with `git pull origin`, then run
If cloning to a subdirectory within another project, you may need to do the
following:

1. Start the server manually (e.g. `node src/node/server.js`)
1. Start the server manually (e.g. `node src/node/server.ts`)
2. Edit the db `filename` in `settings.json` to the relative directory with
the file (e.g. `application/lib/etherpad-lite/var/dirty.db`)
3. Add auto-generated files to the main project `.gitignore`
Expand Down
4 changes: 2 additions & 2 deletions doc/api/hooks_server-side.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
These hooks are called on server-side.

=== loadSettings
Called from: src/node/server.js
Called from: src/node/server.ts

Things in context:

Expand All @@ -11,7 +11,7 @@ Things in context:
Use this hook to receive the global settings in your plugin.

=== shutdown
Called from: src/node/server.js
Called from: src/node/server.ts

Things in context: None

Expand Down
2 changes: 1 addition & 1 deletion src/bin/deb-src/sysroot/etc/init/etherpad.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end script

script
cd $EPHOME/
exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node src/node/server.js \
exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node src/node/server.ts \
>> $EPLOGS/access.log \
2>> $EPLOGS/error.log
echo "Etherpad is running on http://localhost:9001 - To change settings edit /opt/etherpad/settings.json"
Expand Down
Empty file modified src/bin/push-after-release.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ src/bin/installDeps.sh "$@" || exit 1
# Move to the node folder and start
log "Starting Etherpad..."

exec node src/node/server.js "$@"
exec npm run dev --prefix ./src "$@"
2 changes: 1 addition & 1 deletion src/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Module file names start with a capital letter and uses camelCase

# Where does it start?

server.js is started directly
server.ts is started directly
6 changes: 3 additions & 3 deletions src/node/db/DB.js → src/node/db/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const ueberDB = require('ueberdb2');
const settings = require('../utils/Settings');
const log4js = require('log4js');
const stats = require('../stats');
const stats = require('../stats')

const logger = log4js.getLogger('ueberDB');

Expand All @@ -47,13 +47,13 @@ exports.init = async () => {
}
for (const fn of ['get', 'set', 'findKeys', 'getSub', 'setSub', 'remove']) {
const f = exports.db[fn];
exports[fn] = async (...args) => await f.call(exports.db, ...args);
exports[fn] = async (...args:string[]) => await f.call(exports.db, ...args);
Object.setPrototypeOf(exports[fn], Object.getPrototypeOf(f));
Object.defineProperties(exports[fn], Object.getOwnPropertyDescriptors(f));
}
};

exports.shutdown = async (hookName, context) => {
exports.shutdown = async (hookName: string, context:any) => {
if (exports.db != null) await exports.db.close();
exports.db = null;
logger.log('Database closed');
Expand Down
13 changes: 7 additions & 6 deletions src/node/db/SessionStore.js → src/node/db/SessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class SessionStore extends Store {
for (const {timeout} of this._expirations.values()) clearTimeout(timeout);
}

async _updateExpirations(sid, sess, updateDbExp = true) {
async _updateExpirations(sid: string, sess: any, updateDbExp = true) {
const exp = this._expirations.get(sid) || {};
clearTimeout(exp.timeout);
// @ts-ignore
const {cookie: {expires} = {}} = sess || {};
if (expires) {
const sessExp = new Date(expires).getTime();
Expand All @@ -63,23 +64,23 @@ class SessionStore extends Store {
return sess;
}

async _write(sid, sess) {
async _write(sid: string, sess: any) {
await DB.set(`sessionstorage:${sid}`, sess);
}

async _get(sid) {
async _get(sid: string) {
logger.debug(`GET ${sid}`);
const s = await DB.get(`sessionstorage:${sid}`);
return await this._updateExpirations(sid, s);
}

async _set(sid, sess) {
async _set(sid: string, sess:any) {
logger.debug(`SET ${sid}`);
sess = await this._updateExpirations(sid, sess);
if (sess != null) await this._write(sid, sess);
}

async _destroy(sid) {
async _destroy(sid:string) {
logger.debug(`DESTROY ${sid}`);
clearTimeout((this._expirations.get(sid) || {}).timeout);
this._expirations.delete(sid);
Expand All @@ -89,7 +90,7 @@ class SessionStore extends Store {
// Note: express-session might call touch() before it calls set() for the first time. Ideally this
// would behave like set() in that case but it's OK if it doesn't -- express-session will call
// set() soon enough.
async _touch(sid, sess) {
async _touch(sid: string, sess:any) {
logger.debug(`TOUCH ${sid}`);
sess = await this._updateExpirations(sid, sess, false);
if (sess == null) return; // Already expired.
Expand Down
4 changes: 2 additions & 2 deletions src/node/handler/PadMessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const log4js = require('log4js');
const messageLogger = log4js.getLogger('message');
const accessLogger = log4js.getLogger('access');
const hooks = require('../../static/js/pluginfw/hooks.js');
const stats = require('../stats');
const stats = require('../stats')
const assert = require('assert').strict;
const {RateLimiterMemory} = require('rate-limiter-flexible');
const webaccess = require('../hooks/express/webaccess');
Expand Down Expand Up @@ -133,7 +133,7 @@ class Channels {
const padChannels = new Channels((ch, {socket, message}) => handleUserChanges(socket, message));

/**
* This Method is called by server.js to tell the message handler on which socket it should send
* This Method is called by server.ts to tell the message handler on which socket it should send
* @param socket_io The Socket
*/
exports.setSocketIO = (socket_io) => {
Expand Down
2 changes: 1 addition & 1 deletion src/node/handler/SocketIORouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

const log4js = require('log4js');
const settings = require('../utils/Settings');
const stats = require('../stats');
const stats = require('../../node/stats')

const logger = log4js.getLogger('socket.io');

Expand Down
44 changes: 25 additions & 19 deletions src/node/hooks/express.js → src/node/hooks/express.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
'use strict';

const _ = require('underscore');
const SecretRotator = require('../security/SecretRotator');
const cookieParser = require('cookie-parser');
const events = require('events');
const express = require('express');
const expressSession = require('express-session');
const fs = require('fs');
import {Socket} from "node:net";
import type {MapArrayType} from "../types/MapType";

import _ from 'underscore';
// @ts-ignore
import cookieParser from 'cookie-parser';
import events from 'events';
import express from 'express';
// @ts-ignore
import expressSession from 'express-session';
import fs from 'fs';
const hooks = require('../../static/js/pluginfw/hooks');
const log4js = require('log4js');
import log4js from 'log4js';
const SessionStore = require('../db/SessionStore');
const settings = require('../utils/Settings');
const stats = require('../stats');
const util = require('util');
const stats = require('../stats')
import util from 'util';
const webaccess = require('./express/webaccess');

let secretRotator = null;
import SecretRotator from '../security/SecretRotator';

let secretRotator: SecretRotator|null = null;
const logger = log4js.getLogger('http');
let serverName;
let sessionStore;
const sockets = new Set();
let serverName:string;
let sessionStore: { shutdown: () => void; } | null;
const sockets:Set<Socket> = new Set();
const socketsEvents = new events.EventEmitter();
const startTime = stats.settableGauge('httpStartTime');

Expand Down Expand Up @@ -101,7 +107,7 @@ exports.restartServer = async () => {
console.log(`SSL -- server key file: ${settings.ssl.key}`);
console.log(`SSL -- Certificate Authority's certificate file: ${settings.ssl.cert}`);

const options = {
const options: MapArrayType<any> = {
key: fs.readFileSync(settings.ssl.key),
cert: fs.readFileSync(settings.ssl.cert),
};
Expand Down Expand Up @@ -163,7 +169,7 @@ exports.restartServer = async () => {
app.use((req, res, next) => {
const stopWatch = stats.timer('httpRequests').start();
const sendFn = res.send.bind(res);
res.send = (...args) => { stopWatch.end(); sendFn(...args); };
res.send = (...args) => { stopWatch.end(); return sendFn(...args); };
next();
});

Expand All @@ -173,7 +179,7 @@ exports.restartServer = async () => {
// anyway.
if (!(settings.loglevel === 'WARN' && settings.loglevel === 'ERROR')) {
app.use(log4js.connectLogger(logger, {
level: log4js.levels.DEBUG,
level: log4js.levels.DEBUG.levelStr,
format: ':status, :method :url',
}));
}
Expand Down Expand Up @@ -237,7 +243,7 @@ exports.restartServer = async () => {
hooks.aCallAll('expressConfigure', {app}),
hooks.aCallAll('expressCreateServer', {app, server: exports.server}),
]);
exports.server.on('connection', (socket) => {
exports.server.on('connection', (socket:Socket) => {
sockets.add(socket);
socketsEvents.emit('updated');
socket.on('close', () => {
Expand All @@ -250,6 +256,6 @@ exports.restartServer = async () => {
logger.info('HTTP server listening for connections');
};

exports.shutdown = async (hookName, context) => {
exports.shutdown = async (hookName:string, context: any) => {
await closeServer();
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const eejs = require('../../eejs');
import {ArgsExpressType} from "../../types/ArgsExpressType";

const eejs = require('../../eejs');

/**
* Add the admin navigation link
Expand All @@ -9,8 +10,8 @@ const eejs = require('../../eejs');
* @param {Function} cb the callback function
* @return {*}
*/
exports.expressCreateServer = (hookName, args, cb) => {
args.app.get('/admin', (req, res) => {
exports.expressCreateServer = (hookName:string, args: ArgsExpressType, cb:Function): any => {
args.app.get('/admin', (req:any, res:any) => {
if ('/' !== req.path[req.path.length - 1]) return res.redirect('./admin/');
res.send(eejs.require('ep_etherpad-lite/templates/admin/index.html', {req}));
});
Expand Down
Loading