Commit 8ed4d6592a55d0a3666ededdfc213981ad73514b

Authored by Geoffrey PREUD'HOMME
1 parent 8bb44ece

Favicon et meilleur routage

1 var path = require('path'); 1 var path = require('path');
2 var api = require('./routes/ApiRtes'); 2 var api = require('./routes/ApiRtes');
  3 +var favicon = require('serve-favicon');
  4 +var express = require('express');
3 5
4 module.exports = function (app) { 6 module.exports = function (app) {
5 7
  8 + // Statique
  9 + app.use(favicon(path.normalize(__dirname + '/../public/favicon.ico')));
  10 + app.use(express.static(path.normalize(__dirname + '/../public')));
  11 +
  12 + // API
6 app.use('/api/', api); 13 app.use('/api/', api);
7 14
  15 + // Défaut
8 app.get('*', function (req, res) { 16 app.get('*', function (req, res) {
9 if (req.accepts('text/html')) { 17 if (req.accepts('text/html')) {
10 res.sendFile('public/views/index.html', { 18 res.sendFile('public/views/index.html', {
@@ -15,6 +23,7 @@ module.exports = function (app) { @@ -15,6 +23,7 @@ module.exports = function (app) {
15 } 23 }
16 }); 24 });
17 25
  26 + // Mauvaise requête
18 app.all('*', function (req, res) { 27 app.all('*', function (req, res) {
19 res.send(405).end(); 28 res.send(405).end();
20 }); 29 });
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 "mongoose": "^4.0.1", 11 "mongoose": "^4.0.1",
12 "node-cache": "^1.1.0", 12 "node-cache": "^1.1.0",
13 "node-line-reader": "0.0.2", 13 "node-line-reader": "0.0.2",
  14 + "serve-favicon": "^2.2.0",
14 "ssh2": "^0.4.6", 15 "ssh2": "^0.4.6",
15 "ursa": "^0.8.4" 16 "ursa": "^0.8.4"
16 } 17 }
public/favicon.ico 0 → 100644
No preview for this file type
@@ -23,9 +23,6 @@ app.use(bodyParser.urlencoded({ @@ -23,9 +23,6 @@ app.use(bodyParser.urlencoded({
23 // Cookie-parser 23 // Cookie-parser
24 app.use(cookieParser()); 24 app.use(cookieParser());
25 25
26 -// Dossier public  
27 -app.use(express.static(__dirname + '/public'));  
28 -  
29 // Routes 26 // Routes
30 require('./app/routes')(app); 27 require('./app/routes')(app);
31 28