Commit 8ed4d6592a55d0a3666ededdfc213981ad73514b

Authored by Geoffrey PREUD'HOMME
1 parent 8bb44ece

Favicon et meilleur routage

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