mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 16:36:15 -04:00
Fixed index html page
This commit is contained in:
parent
550a29f3e6
commit
32a4068468
4 changed files with 51 additions and 21 deletions
|
@ -111,7 +111,7 @@ const convertTypescript = (content: string) => {
|
|||
}
|
||||
}
|
||||
|
||||
const handleLiveReload = async (args: any, padString: string, timeSliderString: string ) => {
|
||||
const handleLiveReload = async (args: any, padString: string, timeSliderString: string, indexString: any) => {
|
||||
const chokidar = await import('chokidar')
|
||||
const watcher = chokidar.watch(path.join(settings.root, 'src', 'static', 'js'));
|
||||
let routeHandlers: { [key: string]: Function } = {};
|
||||
|
@ -130,6 +130,8 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString:
|
|||
pad: req.path.split('/')[2]
|
||||
}
|
||||
routeHandlers['/p/:pad/timeslider'](req, res);
|
||||
} else if (req.path == "/"){
|
||||
routeHandlers['/'](req, res);
|
||||
} else if (routeHandlers[req.path]) {
|
||||
routeHandlers[req.path](req, res);
|
||||
} else {
|
||||
|
@ -138,6 +140,17 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString:
|
|||
});
|
||||
|
||||
function handleUpdate() {
|
||||
|
||||
convertTypescriptWatched(indexString, (output, hash) => {
|
||||
setRouteHandler('/watch/index', (req: any, res: any) => {
|
||||
res.header('Content-Type', 'application/javascript');
|
||||
res.send(output)
|
||||
})
|
||||
setRouteHandler('/', (req: any, res: any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/index.html', {req, entrypoint: '/watch/index?hash=' + hash, settings}));
|
||||
})
|
||||
})
|
||||
|
||||
convertTypescriptWatched(padString, (output, hash) => {
|
||||
console.log("New pad hash is", hash)
|
||||
setRouteHandler('/watch/pad', (req: any, res: any) => {
|
||||
|
@ -145,6 +158,9 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString:
|
|||
res.send(output)
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
setRouteHandler("/p/:pad", (req: any, res: any, next: Function) => {
|
||||
// The below might break for pads being rewritten
|
||||
const isReadOnly = !webaccess.userCanModify(req.params.pad, req);
|
||||
|
@ -228,12 +244,6 @@ const convertTypescriptWatched = (content: string, cb: (output:string, hash: str
|
|||
}
|
||||
|
||||
exports.expressCreateServer = async (hookName: string, args: any, cb: Function) => {
|
||||
// serve index.html under /
|
||||
args.app.get('/', (req: any, res: any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/index.html', {req}));
|
||||
});
|
||||
|
||||
|
||||
const padString = eejs.require('ep_etherpad-lite/templates/padBootstrap.js', {
|
||||
pluginModules: (() => {
|
||||
const pluginModules = new Set();
|
||||
|
@ -248,6 +258,9 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function)
|
|||
settings,
|
||||
})
|
||||
|
||||
const indexString = eejs.require('ep_etherpad-lite/templates/indexBootstrap.js', {
|
||||
})
|
||||
|
||||
const timeSliderString = eejs.require('ep_etherpad-lite/templates/timeSliderBootstrap.js', {
|
||||
pluginModules: (() => {
|
||||
const pluginModules = new Set();
|
||||
|
@ -268,19 +281,27 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function)
|
|||
|
||||
let fileNamePad: string
|
||||
let fileNameTimeSlider: string
|
||||
let fileNameIndex: string
|
||||
if(process.env.NODE_ENV === "production"){
|
||||
const padSliderWrite = convertTypescript(padString)
|
||||
const timeSliderWrite = convertTypescript(timeSliderString)
|
||||
const indexWrite = convertTypescript(indexString)
|
||||
|
||||
fileNamePad = `padbootstrap-${padSliderWrite.hash}.min.js`
|
||||
fileNameTimeSlider = `timeSliderBootstrap-${timeSliderWrite.hash}.min.js`
|
||||
fileNameIndex = `indexBootstrap-${indexWrite.hash}.min.js`
|
||||
const pathNamePad = path.join(outdir, fileNamePad)
|
||||
const pathNameTimeSlider = path.join(outdir, fileNameTimeSlider)
|
||||
const pathNameIndex = path.join(outdir, 'index.js')
|
||||
|
||||
if (!fs.existsSync(pathNamePad)) {
|
||||
fs.writeFileSync(pathNamePad, padSliderWrite.output);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(pathNameIndex)) {
|
||||
fs.writeFileSync(pathNameIndex, indexWrite.output);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(pathNameTimeSlider)) {
|
||||
fs.writeFileSync(pathNameTimeSlider,timeSliderWrite.output)
|
||||
}
|
||||
|
@ -289,10 +310,19 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function)
|
|||
res.sendFile(pathNamePad)
|
||||
})
|
||||
|
||||
args.app.get("/"+fileNameIndex, (req: any, res: any) => {
|
||||
res.sendFile(pathNameIndex)
|
||||
})
|
||||
|
||||
args.app.get("/"+fileNameTimeSlider, (req: any, res: any) => {
|
||||
res.sendFile(pathNameTimeSlider)
|
||||
})
|
||||
|
||||
// serve index.html under /
|
||||
args.app.get('/', (req: any, res: any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/index.html', {req, settings, entrypoint: "/"+fileNameIndex}));
|
||||
});
|
||||
|
||||
|
||||
// serve pad.html under /p
|
||||
args.app.get('/p/:pad', (req: any, res: any, next: Function) => {
|
||||
|
@ -326,7 +356,7 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function)
|
|||
}));
|
||||
});
|
||||
} else {
|
||||
await handleLiveReload(args, padString, timeSliderString)
|
||||
await handleLiveReload(args, padString, timeSliderString, indexString)
|
||||
}
|
||||
|
||||
// The client occasionally polls this endpoint to get an updated expiration for the express_sid
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue