diff --git a/src/server.aot.ts b/src/server.aot.ts index 9d8b985f3a..7df96cb3b9 100644 --- a/src/server.aot.ts +++ b/src/server.aot.ts @@ -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')}` diff --git a/src/server.ts b/src/server.ts index cba7f5dac6..5c4250c2f5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,11 +7,11 @@ import 'ts-helpers'; import './__workaround.node'; // temporary until 2.1.1 things are patched in Core import * as path from 'path'; +import * as morgan from 'morgan'; import * as express from 'express'; import * as bodyParser from 'body-parser'; -import * as cookieParser from 'cookie-parser'; -import * as morgan from 'morgan'; import * as compression from 'compression'; +import * as cookieParser from 'cookie-parser'; // Angular 2 import { enableProdMode } from '@angular/core'; @@ -59,6 +59,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 })); // @@ -75,7 +76,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')}`