routes.js
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var path = require('path');
var api = require('./routes/ApiRtes');
var favicon = require('serve-favicon');
var express = require('express');
var compression = require('compression');
module.exports = function (app) {
app.use(compression({
filter: function shouldCompress(req, res) {
if (req.headers['x-no-compression']) {
return false;
}
return compression.filter(req, res);
}
}));
// Statique
app.use(favicon(path.normalize(__dirname + '/../public/favicon.ico')));
app.use(express.static(path.normalize(__dirname + '/../public')));
// API
app.use('/api/', api);
// Défaut
app.get('*', function (req, res) {
if (req.accepts('text/html')) {
res.sendFile('public/views/index.html', {
root: path.normalize(__dirname + '/..')
});
} else {
res.send(404).end();
}
});
// Mauvaise requête
app.all('*', function (req, res) {
res.send(405).end();
});
};