2021-01-21 21:06:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-23 13:24:19 -05:00
|
|
|
const log4js = require('log4js');
|
|
|
|
const clientLogger = log4js.getLogger('client');
|
2022-01-28 21:16:05 -05:00
|
|
|
const {Formidable} = require('formidable');
|
2020-11-23 13:24:19 -05:00
|
|
|
const apiHandler = require('../../handler/APIHandler');
|
2021-10-07 19:47:43 -04:00
|
|
|
const util = require('util');
|
2012-02-25 15:20:31 +01:00
|
|
|
|
2024-02-05 21:13:02 +01:00
|
|
|
exports.expressPreSession = async (hookName:string, {app}:any) => {
|
2020-11-23 13:24:19 -05:00
|
|
|
// The Etherpad client side sends information about how a disconnect happened
|
2024-02-05 21:13:02 +01:00
|
|
|
app.post('/ep/pad/connection-diagnostic-info', async (req:any, res:any) => {
|
2023-08-05 15:48:23 +02:00
|
|
|
const [fields, files] = await (new Formidable({})).parse(req);
|
|
|
|
clientLogger.info(`DIAGNOSTIC-INFO: ${fields.diagnosticInfo}`);
|
|
|
|
res.end('OK');
|
2012-02-25 15:20:31 +01:00
|
|
|
});
|
|
|
|
|
2024-02-05 21:13:02 +01:00
|
|
|
const parseJserrorForm = async (req:any) => {
|
2022-01-28 21:16:05 -05:00
|
|
|
const form = new Formidable({
|
|
|
|
maxFileSize: 1, // Files are not expected. Not sure if 0 means unlimited, so 1 is used.
|
|
|
|
});
|
2023-08-05 15:48:23 +02:00
|
|
|
const [fields, files] = await form.parse(req);
|
|
|
|
return fields.errorInfo;
|
|
|
|
};
|
2021-10-07 19:46:07 -04:00
|
|
|
|
2020-11-23 13:24:19 -05:00
|
|
|
// The Etherpad client side sends information about client side javscript errors
|
2024-02-05 21:13:02 +01:00
|
|
|
app.post('/jserror', (req:any, res:any, next:Function) => {
|
2021-10-07 19:46:07 -04:00
|
|
|
(async () => {
|
|
|
|
const data = JSON.parse(await parseJserrorForm(req));
|
2021-10-07 19:47:43 -04:00
|
|
|
clientLogger.warn(`${data.msg} --`, {
|
2024-02-05 21:13:02 +01:00
|
|
|
[util.inspect.custom]: (depth: number, options:any) => {
|
2021-10-07 19:47:43 -04:00
|
|
|
// Depth is forced to infinity to ensure that all of the provided data is logged.
|
2021-10-07 19:47:59 -04:00
|
|
|
options = Object.assign({}, options, {depth: Infinity, colors: true});
|
2021-10-07 19:47:43 -04:00
|
|
|
return util.inspect(data, options);
|
|
|
|
},
|
|
|
|
});
|
2020-11-23 13:24:19 -05:00
|
|
|
res.end('OK');
|
2021-10-07 19:46:07 -04:00
|
|
|
})().catch((err) => next(err || new Error(err)));
|
2012-02-25 15:20:31 +01:00
|
|
|
});
|
2018-03-23 11:17:39 +00:00
|
|
|
|
2020-11-23 13:24:19 -05:00
|
|
|
// Provide a possibility to query the latest available API version
|
2024-02-05 21:13:02 +01:00
|
|
|
app.get('/api', (req:any, res:any) => {
|
2020-11-23 13:24:19 -05:00
|
|
|
res.json({currentVersion: apiHandler.latestApiVersion});
|
2013-02-12 21:47:40 +01:00
|
|
|
});
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|