mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Removed brotli compression. Enable async and preboot.
This commit is contained in:
@@ -8,16 +8,11 @@ import './__workaround.node'; // temporary until 2.1.1 things are patched in Cor
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as morgan from 'morgan';
|
||||
import * as express from 'express';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import * as compression from 'compression';
|
||||
import * as cookieParser from 'cookie-parser';
|
||||
import * as morgan from 'morgan';
|
||||
import * as mcache from 'memory-cache';
|
||||
|
||||
const { gzipSync } = require('zlib');
|
||||
const accepts = require('accepts');
|
||||
const { compressSync } = require('iltorb');
|
||||
const interceptor = require('express-interceptor');
|
||||
|
||||
// Angular 2
|
||||
import { enableProdMode } from '@angular/core';
|
||||
@@ -54,38 +49,7 @@ app.set('json spaces', 2);
|
||||
|
||||
app.use(cookieParser('Angular 2 Universal'));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use(interceptor((req, res) => ({
|
||||
// don't compress responses with this request header
|
||||
isInterceptable: () => (!req.headers['x-no-compression']),
|
||||
intercept: (body, send) => {
|
||||
const encodings = new Set(accepts(req).encodings());
|
||||
const bodyBuffer = new Buffer(body);
|
||||
// url specific key for response cache
|
||||
const key = '__response__' + req.originalUrl || req.url;
|
||||
let output = bodyBuffer;
|
||||
// check if cache exists
|
||||
if (mcache.get(key) === null) {
|
||||
// check for encoding support
|
||||
if (encodings.has('br')) {
|
||||
// brotli
|
||||
res.setHeader('Content-Encoding', 'br');
|
||||
output = compressSync(bodyBuffer);
|
||||
mcache.put(key, { output, encoding: 'br' });
|
||||
} else if (encodings.has('gzip')) {
|
||||
// gzip
|
||||
res.setHeader('Content-Encoding', 'gzip');
|
||||
output = gzipSync(bodyBuffer);
|
||||
mcache.put(key, { output, encoding: 'gzip' });
|
||||
}
|
||||
} else {
|
||||
const { output, encoding } = mcache.get(key);
|
||||
res.setHeader('Content-Encoding', encoding);
|
||||
send(output);
|
||||
}
|
||||
send(output);
|
||||
}
|
||||
})));
|
||||
app.use(compression());
|
||||
|
||||
const accessLogStream = fs.createWriteStream(ROOT + '/morgan.log', { flags: 'a' })
|
||||
|
||||
@@ -102,6 +66,7 @@ function cacheControl(req, res, next) {
|
||||
// Serve static files
|
||||
app.use('/assets', cacheControl, express.static(path.join(__dirname, 'assets'), { maxAge: 30 }));
|
||||
app.use('/styles', cacheControl, express.static(path.join(__dirname, 'styles'), { maxAge: 30 }));
|
||||
|
||||
app.use(cacheControl, express.static(path.join(ROOT, 'dist/client'), { index: false }));
|
||||
|
||||
//
|
||||
@@ -118,7 +83,8 @@ function ngApp(req, res) {
|
||||
req,
|
||||
res,
|
||||
// time: true, // use this to determine what part of your app is slow only in development
|
||||
preboot: false,
|
||||
async: true,
|
||||
preboot: true,
|
||||
baseUrl: '/',
|
||||
requestUrl: req.originalUrl,
|
||||
originUrl: `http://localhost:${app.get('port')}`
|
||||
|
Reference in New Issue
Block a user