Commit 18dc0c63c39d09c025bd1bdb19c2af818ad767f5
1 parent
fb8f1174
Utilisation de la compression
Showing
2 changed files
with
11 additions
and
0 deletions
Show diff stats
app/routes.js
@@ -2,9 +2,19 @@ var path = require('path'); | @@ -2,9 +2,19 @@ var path = require('path'); | ||
2 | var api = require('./routes/ApiRtes'); | 2 | var api = require('./routes/ApiRtes'); |
3 | var favicon = require('serve-favicon'); | 3 | var favicon = require('serve-favicon'); |
4 | var express = require('express'); | 4 | var express = require('express'); |
5 | +var compression = require('compression'); | ||
5 | 6 | ||
6 | module.exports = function (app) { | 7 | module.exports = function (app) { |
7 | 8 | ||
9 | + app.use(compression({ | ||
10 | + filter: function shouldCompress(req, res) { | ||
11 | + if (req.headers['x-no-compression']) { | ||
12 | + return false; | ||
13 | + } | ||
14 | + return compression.filter(req, res); | ||
15 | + } | ||
16 | + })); | ||
17 | + | ||
8 | // Statique | 18 | // Statique |
9 | app.use(favicon(path.normalize(__dirname + '/../public/favicon.ico'))); | 19 | app.use(favicon(path.normalize(__dirname + '/../public/favicon.ico'))); |
10 | app.use(express.static(path.normalize(__dirname + '/../public'))); | 20 | app.use(express.static(path.normalize(__dirname + '/../public'))); |
package.json
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | "dependencies": { | 5 | "dependencies": { |
6 | "async": "^0.9.0", | 6 | "async": "^0.9.0", |
7 | "body-parser": "^1.12.2", | 7 | "body-parser": "^1.12.2", |
8 | + "compression": "^1.4.3", | ||
8 | "connect-mongo": "^0.8.0", | 9 | "connect-mongo": "^0.8.0", |
9 | "cookie-parser": "^1.3.4", | 10 | "cookie-parser": "^1.3.4", |
10 | "express": "^4.12.3", | 11 | "express": "^4.12.3", |