-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (60 loc) · 2.14 KB
/
app.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
//Importation des modules
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var session = require('express-session');
var passport = require('passport');
var auth = require('./config/passport.js');
var flash = require('connect-flash');
//Connection à la base de donnée
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGOLAB_URI || 'mongodb://localhost/db');
//Routes
var routes = require('./app/routes/index');
var connexion= require('./app/routes/connexion.js');
var user = require('./app/routes/user.js');
var contact = require('./app/routes/contact.js');
var section = require('./app/routes/section.js');
var enfant = require('./app/routes/enfant.js');
var blog = require('./app/routes/blog.js');
var app = express();
// uncomment after placing your favicon in /public
app.use(favicon(path.join(__dirname, 'public/img', 'scout.png')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: 'louvainlaneuve',
resave: true,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
var auth = auth();
//Pour avoir accès à GET, POST, PUT et DELETE
app.use(methodOverride(function(req, res){
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
var method = req.body._method;
delete req.body._method;
return method;
}
}));
app.use('/api/connexion', connexion);
app.use('/api/user', user);
app.use('/api/contact', contact);
app.use('/api/section', section);
app.use('/api/enfant', enfant);
app.use('/api/blog', blog);
app.use('/api', routes);
app.get('*', function(req, res){
res.sendFile(path.join(__dirname, '/public/modules/base/views/index.html'));
});
module.exports = app;