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');
|
|
|
|
const formidable = require('formidable');
|
|
|
|
const apiHandler = require('../../handler/APIHandler');
|
2012-02-25 15:20:31 +01:00
|
|
|
|
2021-01-21 21:06:52 +00:00
|
|
|
exports.expressCreateServer = (hookName, args, cb) => {
|
2020-11-23 13:24:19 -05:00
|
|
|
// The Etherpad client side sends information about how a disconnect happened
|
|
|
|
args.app.post('/ep/pad/connection-diagnostic-info', (req, res) => {
|
|
|
|
new formidable.IncomingForm().parse(req, (err, fields, files) => {
|
|
|
|
clientLogger.info(`DIAGNOSTIC-INFO: ${fields.diagnosticInfo}`);
|
|
|
|
res.end('OK');
|
2012-02-25 15:20:31 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-07 19:46:07 -04:00
|
|
|
const parseJserrorForm = async (req) => await new Promise((resolve, reject) => {
|
|
|
|
const form = new formidable.IncomingForm();
|
2021-10-07 19:46:38 -04:00
|
|
|
form.maxFileSize = 1; // Files are not expected. Not sure if 0 means unlimited, so 1 is used.
|
2021-10-07 19:46:07 -04:00
|
|
|
form.on('error', (err) => reject(err));
|
|
|
|
form.parse(req, (err, fields) => err != null ? reject(err) : resolve(fields.errorInfo));
|
|
|
|
});
|
|
|
|
|
2020-11-23 13:24:19 -05:00
|
|
|
// The Etherpad client side sends information about client side javscript errors
|
2021-10-07 19:46:07 -04:00
|
|
|
args.app.post('/jserror', (req, res, next) => {
|
|
|
|
(async () => {
|
|
|
|
const data = JSON.parse(await parseJserrorForm(req));
|
2020-11-23 13:24:19 -05:00
|
|
|
clientLogger.warn(`${data.msg} --`, data);
|
|
|
|
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
|
|
|
|
args.app.get('/api', (req, res) => {
|
|
|
|
res.json({currentVersion: apiHandler.latestApiVersion});
|
2013-02-12 21:47:40 +01:00
|
|
|
});
|
2020-10-10 22:51:26 -04:00
|
|
|
|
|
|
|
return cb();
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|