diff --git a/app/routes/ApiRtes.js b/app/routes/ApiRtes.js index dabe588..8432a7c 100644 --- a/app/routes/ApiRtes.js +++ b/app/routes/ApiRtes.js @@ -4,12 +4,16 @@ var DecryptServ = require('../services/DecryptServ'); var ConvsServ = require('../services/ConvsServ'); var MessServ = require('../services/MessServ'); var fs = require('fs'); +var mongoose = require('mongoose'); var express = require('express'); var session = require('express-session'); var MongoStore = require('connect-mongo')(session); var api = express(); +// Connection à la BDD +mongoose.connect(require('../../config/db').url); + // Authentication reqAuth = function () { return function (req, res, next) { @@ -96,7 +100,9 @@ sessionData = function (session, cb) { }; api.use(session({ - // TODO Session store https://github.com/expressjs/session#compatible-session-stores + store: new MongoStore({ + mongooseConnection: mongoose.connection + }), name: 'membreCool', resave: false, saveUninitialized: true, diff --git a/package.json b/package.json index 04557b2..799f334 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "async": "^0.9.0", "body-parser": "^1.12.2", + "connect-mongo": "^0.8.0", "cookie-parser": "^1.3.4", "express": "^4.12.3", "express-http-proxy": "^0.5.0", diff --git a/server.js b/server.js index 6dc4281..46c5afc 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,5 @@ // Modules ==================================================================== var express = require('express'); -var mongoose = require('mongoose'); var bodyParser = require('body-parser'); // Application ================================================================ @@ -9,10 +8,6 @@ var app = express(); var config = require('./config/config.js'); var port = process.env.PORT || config.port; -// Connection à la BDD -var db = require('./config/db'); -mongoose.connect(db.url); - // Tricks app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ -- libgit2 0.21.2