2021-01-21 21:06:52 +00:00
|
|
|
'use strict';
|
2024-02-05 21:13:02 +01:00
|
|
|
import {ArgsExpressType} from "../../types/ArgsExpressType";
|
2024-03-09 23:07:09 +01:00
|
|
|
import path from "path";
|
|
|
|
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
2012-11-05 12:58:02 +00:00
|
|
|
|
2024-03-09 23:07:09 +01:00
|
|
|
const ADMIN_PATH = path.join(settings.root, 'src', 'templates', 'admin');
|
2023-10-17 12:49:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the admin navigation link
|
|
|
|
* @param hookName {String} the name of the hook
|
|
|
|
* @param args {Object} the object containing the arguments
|
|
|
|
* @param {Function} cb the callback function
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2024-02-05 21:13:02 +01:00
|
|
|
exports.expressCreateServer = (hookName:string, args: ArgsExpressType, cb:Function): any => {
|
2024-03-09 23:07:09 +01:00
|
|
|
args.app.get('/admin/*', (req:any, res:any, next:Function) => {
|
|
|
|
if (req.path.includes('.')) {
|
|
|
|
const relativPath = req.path.split('/admin/')[1];
|
|
|
|
res.sendFile(path.join(ADMIN_PATH, relativPath));
|
|
|
|
} else {
|
|
|
|
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
|
|
|
|
res.header('Expires', '-1');
|
|
|
|
res.header('Pragma', 'no-cache');
|
|
|
|
res.sendFile(path.join(ADMIN_PATH, 'index.html'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
args.app.get('/admin', (req:any, res:any, next:Function) => {
|
|
|
|
if ('/' !== req.path[req.path.length - 1]) return res.redirect('./admin/');
|
|
|
|
})
|
2020-10-10 22:51:26 -04:00
|
|
|
return cb();
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|