Commit 8ed4d6592a55d0a3666ededdfc213981ad73514b
1 parent
8bb44ece
Favicon et meilleur routage
Showing
4 changed files
with
10 additions
and
3 deletions
Show diff stats
app/routes.js
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 | }); |
package.json
@@ -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 | } |
No preview for this file type
server.js
@@ -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 |