| app.js - seedlinux - Torrent indexing tool opensource torrents with share ratio… | |
| git clone git://jay.scot/seedlinux | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| app.js (1510B) | |
| --- | |
| 1 'use strict'; | |
| 2 | |
| 3 if(process.env.NODE_ENV === 'production') { | |
| 4 require ('newrelic'); | |
| 5 } | |
| 6 | |
| 7 const express = require('express'); | |
| 8 const path = require('path'); | |
| 9 const logger = require('morgan'); | |
| 10 const bodyParser = require('body-parser'); | |
| 11 const mongoose = require('mongoose'); | |
| 12 const helmet = require('helmet'); | |
| 13 const compression = require('compression'); | |
| 14 const config = require('./app/config'); | |
| 15 const index = require('./routes/index'); | |
| 16 | |
| 17 const mongoDB = config.dbURI; | |
| 18 mongoose.connect(mongoDB); | |
| 19 | |
| 20 var db = mongoose.connection; | |
| 21 db.on('error', console.error.bind(console, 'MongoDB connection error:')); | |
| 22 | |
| 23 const app = express(); | |
| 24 | |
| 25 // Enable basic security but disable 'Strict-Transport-Security' | |
| 26 app.use(helmet({ | |
| 27 hsts: false | |
| 28 })); | |
| 29 | |
| 30 app.set('views', path.join(__dirname, 'views')); | |
| 31 app.set('view engine', 'pug'); | |
| 32 | |
| 33 // disable the logger in production | |
| 34 if (app.get('env') !== 'production') { | |
| 35 app.use(logger('dev')); | |
| 36 } | |
| 37 | |
| 38 app.use(compression()); | |
| 39 app.use(bodyParser.json()); | |
| 40 app.use(bodyParser.urlencoded({ extended: false })); | |
| 41 app.use(express.static(path.join(__dirname, 'public'))); | |
| 42 | |
| 43 // setup the DB | |
| 44 app.use(function(req,res,next){ | |
| 45 req.db = db; | |
| 46 next(); | |
| 47 }); | |
| 48 | |
| 49 app.use('/', index); | |
| 50 | |
| 51 app.use(function(req, res, next) { | |
| 52 var err = new Error('Not Found'); | |
| 53 err.status = 404; | |
| 54 next(err); | |
| 55 }); | |
| 56 | |
| 57 app.use(function(err, req, res, next) { | |
| 58 res.locals.message = err.message; | |
| 59 res.locals.error = req.app.get('env') === 'development' ? err : {}; | |
| 60 | |
| 61 res.status(err.status || 500); | |
| 62 res.render('error'); | |
| 63 }); | |
| 64 | |
| 65 module.exports = app; |