-
-
Save panpansh/43b23a1cdc493a4cf224 to your computer and use it in GitHub Desktop.
This file contains 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 path = require('path'); | |
var favicon = require('static-favicon'); | |
var logger = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
/* Custom vars */ | |
var log = require('./libs/log')(module); | |
var passport = require('passport'); | |
var helmet = require('helmet'); | |
/* END Custom vars */ | |
var routes = require('./routes/index'); | |
var api = require('./routes/api'); | |
var oauth = require('./routes/oauth'); | |
var app = express(); | |
app.use(helmet.defaults()); | |
app.use(passport.initialize()); | |
// view engine setup | |
app.set('views', path.join(__dirname, 'views')); | |
app.set('view engine', 'jade'); | |
app.use(favicon('./public/images/favicon.ico')); | |
app.use(logger('dev')); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded()); | |
app.use(cookieParser()); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.use('/', routes); | |
app.use('/api', api); | |
app.use('/oauth', oauth); | |
/// catch 404 and forward to error handler | |
app.use(function(req, res, next) { | |
var err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}); | |
/// error handlers | |
// development error handler | |
// will print stacktrace | |
if (app.get('env') === 'development') { | |
app.use(function(err, req, res, next) { | |
res.status(err.status || 500); | |
log.error(res.statusCode, err.message, req.url); | |
res.send(err.status); | |
}); | |
} | |
// production error handler | |
// no stacktraces leaked to user | |
app.use(function(err, req, res, next) { | |
res.status(err.status || 500); | |
log.error(res.statusCode, err.message, req.url); | |
res.send(err.status); | |
}); | |
module.exports = app; |
This file contains 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
{ | |
"name": "ppshApp", | |
"version": "0.0.1", | |
"private": true, | |
"scripts": { | |
"start": "node ./bin/www" | |
}, | |
"dependencies": { | |
"body-parser": "~1.0.0", | |
"cookie-parser": "~1.0.1", | |
"debug": "~0.7.4", | |
"express": "~4.2.0", | |
"faker": "^1.0.0", | |
"helmet": "^0.2.4", | |
"jade": "~1.3.0", | |
"mongoose": "^3.8.12", | |
"morgan": "~1.0.0", | |
"nconf": "^0.6.9", | |
"passport": "^0.2.0", | |
"static-favicon": "~1.0.0", | |
"winston": "^0.7.3" | |
// + others.. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment