From 1db24d07bd2b51df8dd497b4edc20f2496891158 Mon Sep 17 00:00:00 2001 From: Scott Tolksdorf Date: Wed, 23 Nov 2016 23:00:28 -0500 Subject: [PATCH] Adding in the needed libs --- config/default.json | 5 +++++ package.json | 5 ++++- server.js | 30 +++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 config/default.json diff --git a/config/default.json b/config/default.json new file mode 100644 index 0000000..1dc3dcb --- /dev/null +++ b/config/default.json @@ -0,0 +1,5 @@ +{ + "host" : "homebrewery.local.naturalcrit.com:8000", + "naturalcrit_url" : "local.naturalcrit.com:8010", + "secret" : "secret" +} \ No newline at end of file diff --git a/package.json b/package.json index ed466d4..0e66d4b 100644 --- a/package.json +++ b/package.json @@ -16,14 +16,17 @@ "basic-auth": "^1.0.3", "body-parser": "^1.14.2", "classnames": "^2.2.0", + "cookie-parser": "^1.4.3", "express": "^4.13.3", "gulp": "^3.9.0", "gulp-less": "^3.1.0", "gulp-rename": "^1.2.2", + "jwt-simple": "^0.5.1", "lodash": "^4.11.2", "marked": "^0.3.5", "moment": "^2.11.0", "mongoose": "^4.3.3", + "nconf": "^0.8.4", "pico-flux": "^1.1.0", "pico-router": "^1.1.0", "react": "^15.0.2", @@ -33,4 +36,4 @@ "superagent": "^1.6.1", "vitreum": "^3.2.1" } -} \ No newline at end of file +} diff --git a/server.js b/server.js index fb11c0c..0b447dd 100644 --- a/server.js +++ b/server.js @@ -1,24 +1,36 @@ require('app-module-path').addPath('./shared'); const _ = require('lodash'); +const jwt = require('jwt-simple'); const vitreumRender = require('vitreum/render'); -const bodyParser = require('body-parser') const express = require("express"); const app = express(); app.use(express.static(__dirname + '/build')); -app.use(bodyParser.json({limit: '25mb'})); +app.use(require('body-parser').json({limit: '25mb'})); +app.use(require('cookie-parser')()); + +const config = require('nconf') + .argv() + .env({ lowerCase: true }) + .file('environment', { file: `config/${process.env.NODE_ENV}.json` }) + .file('defaults', { file: 'config/default.json' }); + +//DB +require('mongoose') + .connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit') + .connection.on('error', () => { console.log(">>>ERROR: Run Mongodb.exe ya goof!") }); -//Mongoose -//TODO: Celean up -const mongoose = require('mongoose'); -const mongoUri = process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit'; -require('mongoose').connect(mongoUri); -mongoose.connection.on('error', function(){ - console.log(">>>ERROR: Run Mongodb.exe ya goof!"); +//Account MIddleware +router.use((req, res, next) => { + if(req.cookies && req.cookies.nc_session){ + req.user = jwt.decode(req.cookies.nc_session, config.get('secret')); + } + return next(); }); + app.use(require('./server/homebrew.api.js')); app.use(require('./server/admin.api.js'));