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-11 10:15:19 -04:00
|
|
|
var passport = require('passport');
|
2017-10-09 22:01:02 -04:00
|
|
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
mongoose.connect('mongodb://localhost/shimapan', {useMongoClient: true});
|
|
|
|
var db = mongoose.connection;
|
|
|
|
db.on('error', function(err) {
|
|
|
|
if (err)
|
|
|
|
console.log('MongoDB Connection Error: ', err);
|
|
|
|
else
|
|
|
|
console.log('MongoDB Connection Established');
|
|
|
|
|
|
|
|
});
|
|
|
|
db.once('open', function() {
|
|
|
|
console.log('MongoDB Connection Open')
|
|
|
|
});
|
|
|
|
|
2017-10-11 10:15:19 -04:00
|
|
|
require('./config/passport.js');
|
|
|
|
|
2017-10-09 22:01:02 -04:00
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
2017-10-11 10:15:19 -04:00
|
|
|
app.use(passport.initialize());
|
2017-10-09 22:01:02 -04:00
|
|
|
app.use(methodOverride('X-HTTP-Method-Override'));
|
|
|
|
|
2017-10-11 10:15:19 -04:00
|
|
|
app.get('/secret', passport.authenticate('local', { session: false }), function(req, res) {
|
|
|
|
res.json("You cannot see this without a token!");
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
app.listen(port);
|
|
|
|
console.log('Listening on port ', port, '...');
|
|
|
|
|
|
|
|
// Expose app
|
|
|
|
exports = module.exports = app;
|