Created
January 25, 2017 01:21
-
-
Save JBreit/a217c57e2197bb55f250275063e288f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
bodyParser = require('body-parser'), | |
cookieParser = require('cookie-parser'), | |
favicon = require('serve-favicon'), | |
path = require('path'), | |
logger = require('./../utils/logger'), | |
methodOverride = require('method-override'), | |
morgan = require('morgan'), | |
session = require('express-session'), | |
db = require('./config/db'), | |
mongoose = require('mongoose'), | |
connection = mongoose.connection, | |
MongooseStore = require('express-mongoose-store')(session, mongoose), | |
//passport = require('passport'), | |
bluebird = require('bluebird'), | |
index = require('./routes/index'), | |
users = require('./routes/users'), | |
__public = path.join(__dirname, 'public'), | |
app = express(); | |
db.connect(db.url); | |
connection.on('error', console.error.bind(console, 'connection error:')); | |
mongoose.Promise = global.Promise; | |
mongoose.Promise = bluebird; | |
app.enable('verbose errors') | |
.set('view engine', 'hbs') | |
.set('views', path.join(__dirname, 'views')) | |
.set('json spaces', 2) | |
.use(morgan('combined', {steam: logger.stream})) | |
.use(favicon(path.join(__public, 'img', 'favicon.ico'))) | |
.use(bodyParser.urlencoded({extended: true})) | |
.use(bodyParser.json()) | |
.use(cookieParser()) | |
.use(methodOverride('X-HTTP-Override')) | |
.use(express.static(__public)) | |
.use(session({ | |
secret: 'SECRET', | |
resave: true, | |
saveUninitialized: true, | |
cookie: { | |
maxAge: 60 * 60 * 1000 | |
}, | |
store: new MongooseStore({ | |
modelName: 'session', | |
db: mongoose.connection.db, | |
collection: 'sessions', | |
ttl: 14 * 24 * 60 * 60 | |
}) | |
})) | |
.use('/', index) | |
.use('/users', users) | |
.use(function (req, res, next) { | |
'use strict'; | |
var err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}) | |
.use(function (err, req, res, next) { | |
'use strict'; | |
/*res.locals.message = err.message; | |
res.locals.error = req.app.get('env') === 'development' | |
? err | |
: {};*/ | |
res.status(err.status || 500) | |
.render('error', { | |
message: err.message, | |
url: req.originalUrl, | |
error: err | |
}); | |
}); | |
module.exports = app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Can't fully test until I can properly set environments on Windows 7 Pro (64 bit) x86 | |
*/ | |
var normalizePort = require('./../../utils').normalizePort, | |
_defaults = [ | |
/*"NODE_ENV",*/ | |
"HOST", | |
"PORT" | |
]; | |
_defaults.forEach(function (name) { | |
'use strict'; | |
if (!process.env[name]) { | |
throw new Error('Environment variable ' + name + ' is missing'); | |
} | |
}); | |
var config = { | |
env: process.env.NODE_ENV, | |
server: { | |
host: process.env.HOST || 'http://127.0.0.1', | |
port: normalizePort(process.env.PORT || 8080) | |
} | |
}; | |
module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
exports.connect = function (url) { | |
'use strict'; | |
return mongoose.connect(url); | |
}; | |
exports.url = 'mongodb://127.0.0.1:27017/innermind' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
router = express.Router(); | |
router | |
.get('/', function (req, res) { | |
'use strict'; | |
res.status(200) | |
.render('index', { | |
meta: {}, | |
title: 'Inner Mind Consulting' | |
}); | |
}); | |
module.exports = router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var router = express.Router(); | |
router | |
.get('/', function (req, res) { | |
'use strict'; | |
res.status(200) | |
.render('users', { | |
meta: {}, | |
title: 'Users' | |
}); | |
}); | |
module.exports = router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('./app'), | |
/*debug = require('debug')('mean:server'),*/ | |
http = require('http'), | |
utils = require('./utils'), | |
logger = utils.logger, | |
normalizePort = utils.normalizePort, | |
host = process.env.HOST || '127.0.0.1', | |
port, | |
server; | |
port = normalizePort(process.env.PORT || 8080); | |
server = http.createServer(app) | |
.on('error', function (err) { | |
'use strict'; | |
if (err.syscall !== 'listen') { | |
throw err; | |
} | |
var bind = typeof port === 'string' | |
? 'Pipe ' + port | |
: 'Port ' + port; | |
switch (err.code) { | |
case 'EACCES': | |
console.error(bind + ' requires elevated privileges'); | |
process.exit(1); | |
break; | |
case 'EADDRINUSE': | |
console.error(bind + ' is already in use'); | |
process.exit(1); | |
break; | |
default: | |
throw err; | |
} | |
}) | |
.on('listening', function () { | |
'use strict'; | |
var addr = server.address(); | |
var bind = typeof addr === 'string' | |
? 'pipe ' + addr | |
: 'port ' + addr.port; | |
//debug('Listening on ' + bind); | |
//logger.debug('> Server listening at http://' + host + ':' + port + '/'); | |
console.log('> Server listening at http://' + host + ':' + port + '/'); | |
}) | |
.listen(port, host); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment