mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Fixed cache server not working due to wrong (#6236)
This commit is contained in:
parent
d0d0d6fc7a
commit
d7869f5014
2 changed files with 13 additions and 10 deletions
|
@ -8,7 +8,7 @@ const minify = require('../../utils/Minify');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||||
const settings = require('../../utils/Settings');
|
const settings = require('../../utils/Settings');
|
||||||
const CachingMiddleware = require('../../utils/caching_middleware');
|
import CachingMiddleware from '../../utils/caching_middleware';
|
||||||
const Yajsml = require('etherpad-yajsml');
|
const Yajsml = require('etherpad-yajsml');
|
||||||
|
|
||||||
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
||||||
|
@ -35,7 +35,9 @@ const getTar = async () => {
|
||||||
exports.expressPreSession = async (hookName:string, {app}:any) => {
|
exports.expressPreSession = async (hookName:string, {app}:any) => {
|
||||||
// Cache both minified and static.
|
// Cache both minified and static.
|
||||||
const assetCache = new CachingMiddleware();
|
const assetCache = new CachingMiddleware();
|
||||||
app.all(/\/javascripts\/(.*)/, assetCache.handle.bind(assetCache));
|
// Cache static assets
|
||||||
|
app.all(/\/js\/(.*)/, assetCache.handle.bind(assetCache));
|
||||||
|
app.all(/\/css\/(.*)/, assetCache.handle.bind(assetCache));
|
||||||
|
|
||||||
// Minify will serve static files compressed (minify enabled). It also has
|
// Minify will serve static files compressed (minify enabled). It also has
|
||||||
// file-specific hacks for ace/require-kernel/etc.
|
// file-specific hacks for ace/require-kernel/etc.
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Buffer = require('buffer').Buffer;
|
import {Buffer} from 'node:buffer'
|
||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
const fsp = fs.promises;
|
const fsp = fs.promises;
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
const zlib = require('zlib');
|
import zlib from 'zlib';
|
||||||
const settings = require('./Settings');
|
const settings = require('./Settings');
|
||||||
const existsSync = require('./path_exists');
|
const existsSync = require('./path_exists');
|
||||||
const util = require('util');
|
import util from 'util';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The crypto module can be absent on reduced node installations.
|
* The crypto module can be absent on reduced node installations.
|
||||||
|
@ -37,10 +37,10 @@ const util = require('util');
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const _crypto = require('crypto');
|
import _crypto from 'crypto';
|
||||||
|
|
||||||
|
|
||||||
let CACHE_DIR = path.join(settings.root, 'var/');
|
let CACHE_DIR: string|undefined = path.join(settings.root, 'var/');
|
||||||
CACHE_DIR = existsSync(CACHE_DIR) ? CACHE_DIR : undefined;
|
CACHE_DIR = existsSync(CACHE_DIR) ? CACHE_DIR : undefined;
|
||||||
|
|
||||||
type Headers = {
|
type Headers = {
|
||||||
|
@ -84,7 +84,7 @@ if (_crypto) {
|
||||||
should replace this.
|
should replace this.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = class CachingMiddleware {
|
export default class CachingMiddleware {
|
||||||
handle(req: any, res: any, next: any) {
|
handle(req: any, res: any, next: any) {
|
||||||
this._handle(req, res, next).catch((err) => next(err || new Error(err)));
|
this._handle(req, res, next).catch((err) => next(err || new Error(err)));
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,7 @@ module.exports = class CachingMiddleware {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fsp.writeFile(`${CACHE_DIR}minified_${cacheKey}`, buffer).catch(() => {}),
|
fsp.writeFile(`${CACHE_DIR}minified_${cacheKey}`, buffer).catch(() => {}),
|
||||||
util.promisify(zlib.gzip)(buffer)
|
util.promisify(zlib.gzip)(buffer)
|
||||||
|
// @ts-ignore
|
||||||
.then((content: string) => fsp.writeFile(`${CACHE_DIR}minified_${cacheKey}.gz`, content))
|
.then((content: string) => fsp.writeFile(`${CACHE_DIR}minified_${cacheKey}.gz`, content))
|
||||||
.catch(() => {}),
|
.catch(() => {}),
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue