Fixed port not available.

This commit is contained in:
SamTV12345 2024-08-19 20:38:20 +02:00
parent dcb07a709d
commit c52b623679
3 changed files with 11 additions and 4 deletions

View file

@ -144,7 +144,7 @@ importers:
src: src:
dependencies: dependencies:
'@etherpad/express-session': '@etherpad/express-session':
specifier: ^1.18.4 specifier: 1.18.4
version: 1.18.4 version: 1.18.4
async: async:
specifier: ^3.2.5 specifier: ^3.2.5

View file

@ -30,7 +30,7 @@
} }
], ],
"dependencies": { "dependencies": {
"@etherpad/express-session": "^1.18.4", "@etherpad/express-session": "1.18.4",
"async": "^3.2.5", "async": "^3.2.5",
"axios": "^1.7.4", "axios": "^1.7.4",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",

View file

@ -17,6 +17,7 @@ import {Http2Server} from "node:http2";
import {SignJWT} from "jose"; import {SignJWT} from "jose";
import {privateKeyExported} from "../../node/security/OAuth2Provider"; import {privateKeyExported} from "../../node/security/OAuth2Provider";
const webaccess = require('../../node/hooks/express/webaccess'); const webaccess = require('../../node/hooks/express/webaccess');
import crypto from 'crypto';
const backups:MapArrayType<any> = {}; const backups:MapArrayType<any> = {};
let agentPromise:Promise<any>|null = null; let agentPromise:Promise<any>|null = null;
@ -74,16 +75,22 @@ export const init = async function () {
'To enable non-test logging, change the loglevel setting to DEBUG.'); 'To enable non-test logging, change the loglevel setting to DEBUG.');
} }
const generateRandomPort = () => {
const minPort = 1024;
const maxPort = 65535;
return crypto.randomInt(minPort, maxPort + 1);
};
// Note: This is only a shallow backup. // Note: This is only a shallow backup.
backups.settings = Object.assign({}, settings); backups.settings = Object.assign({}, settings);
// Start the Etherpad server on a random unused port. // Start the Etherpad server on a random unused port.
settings.port = 0; settings.port = generateRandomPort();
settings.ip = 'localhost'; settings.ip = 'localhost';
settings.importExportRateLimiting = {max: 999999}; settings.importExportRateLimiting = {max: 999999};
settings.commitRateLimiting = {duration: 0.001, points: 1e6}; settings.commitRateLimiting = {duration: 0.001, points: 1e6};
httpServer = await server.start(); httpServer = await server.start();
// @ts-ignore // @ts-ignore
baseUrl = `http://localhost:${httpServer!.address()!.port}`; baseUrl = `http://localhost:${settings.port}`;
logger.debug(`HTTP server at ${baseUrl}`); logger.debug(`HTTP server at ${baseUrl}`);
// Create a supertest user agent for the HTTP server. // Create a supertest user agent for the HTTP server.
agent = supertest(baseUrl) agent = supertest(baseUrl)