1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-10 23:53:31 -05:00
shimapan/server.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-10-09 22:01:02 -04:00
var express = require('express');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var mongoose = require('mongoose');
2017-10-12 17:26:35 -04:00
var morgan = require('morgan');
2017-10-11 10:15:19 -04:00
var passport = require('passport');
2017-10-14 17:49:11 -04:00
var cookieParser = require('cookie-parser');
2017-10-09 22:01:02 -04:00
var app = express();
2017-10-12 17:26:35 -04:00
var config = require('config');
if(config.util.getEnv('NODE_ENV') !== 'test') {
app.use(morgan('combined'));
}
mongoose.Promise = global.Promise;
mongoose.connect(config.dbHost, {useMongoClient: true});
2017-10-09 22:01:02 -04:00
var db = mongoose.connection;
db.on('error', function(err) {
2017-10-12 17:26:35 -04:00
if (err) console.log('MongoDB Connection Error: ', err);
2017-10-09 22:01:02 -04:00
});
2017-10-11 10:15:19 -04:00
require('./config/passport.js');
2017-10-14 17:49:11 -04:00
app.use(cookieParser());
2017-10-09 22:01:02 -04:00
app.use(bodyParser.json());
2017-10-12 17:26:35 -04:00
app.use(bodyParser.json({ type: 'application/json' }));
2017-10-09 22:01:02 -04:00
app.use(bodyParser.urlencoded({ extended: true }));
2017-10-12 17:26:35 -04:00
app.use(bodyParser.text());
2017-10-09 22:01:02 -04:00
app.use(methodOverride('X-HTTP-Method-Override'));
2017-10-12 17:26:35 -04:00
app.use(passport.initialize());
2017-10-09 22:01:02 -04:00
// Set /public to document root
app.use(express.static(__dirname + '/public'));
require('./app/routes')(app);
// Start app
var port = process.env.PORT || 8080;
2017-10-12 17:26:35 -04:00
var server = app.listen(port);
2017-10-09 22:01:02 -04:00
console.log('Listening on port ', port, '...');
// Expose app
2017-10-12 17:26:35 -04:00
exports.db = db;
exports.server = server;
exports.app = app;