mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
Use express for static side hosting.
This commit is contained in:
parent
93a929b5ff
commit
4add6eb313
1 changed files with 5 additions and 17 deletions
|
@ -2,6 +2,7 @@
|
||||||
import {ArgsExpressType} from "../../types/ArgsExpressType";
|
import {ArgsExpressType} from "../../types/ArgsExpressType";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import express from "express";
|
||||||
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
||||||
|
|
||||||
const ADMIN_PATH = path.join(settings.root, 'src', 'templates', 'admin');
|
const ADMIN_PATH = path.join(settings.root, 'src', 'templates', 'admin');
|
||||||
|
@ -14,23 +15,10 @@ const ADMIN_PATH = path.join(settings.root, 'src', 'templates', 'admin');
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
exports.expressCreateServer = (hookName:string, args: ArgsExpressType, cb:Function): any => {
|
exports.expressCreateServer = (hookName:string, args: ArgsExpressType, cb:Function): any => {
|
||||||
args.app.get('/admin/*', (req:any, res:any, next:Function) => {
|
args.app.use('/admin/', express.static(path.join(__dirname, '../../../templates/admin'), {maxAge: 1000 * 60 * 60 * 24}));
|
||||||
if (req.path.includes('.')) {
|
args.app.get('/admin/*', (_request:any, response:any)=>{
|
||||||
const relativPath = req.path.split('/admin/')[1];
|
response.sendFile(path.resolve(__dirname,'../../../templates/admin', 'index.html'));
|
||||||
try {
|
} )
|
||||||
if (fs.statSync(path.join(ADMIN_PATH, relativPath)).isFile()) {
|
|
||||||
res.sendFile(path.join(ADMIN_PATH, relativPath));
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
res.status(404).send('404: Not Found');
|
|
||||||
}
|
|
||||||
} 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) => {
|
args.app.get('/admin', (req:any, res:any, next:Function) => {
|
||||||
if ('/' !== req.path[req.path.length - 1]) return res.redirect('./admin/');
|
if ('/' !== req.path[req.path.length - 1]) return res.redirect('./admin/');
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue