-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
59 lines (49 loc) · 1.63 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Satellizer Node.js Example
* (c) 2015 Sahat Yalkabov
* License: MIT
* Modified by: Calvin Webster
*/
var path = require('path');
var async = require('async');
var bodyParser = require('body-parser');
var express = require('express');
var logger = require('morgan');
var mongoose = require('mongoose');
var config = require('./config');
var User = require('./entities/User');
var authRoutes = require('./routes/auth');
var crudRoutes = require('./routes/apiCrud');
var profileRoutes = require('./routes/profile');
mongoose.connect(config.MONGO_URI);
mongoose.connection.on('error', function() {
console.error('MongoDB Connection Error. Please make sure that MongoDB is running.');
});
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// Force HTTPS on Heroku
if (app.get('env') === 'production') {
app.use(function(req, res, next) {
var protocol = req.get('x-forwarded-proto');
protocol === 'https' ? next() : res.redirect('https://' + req.hostname + req.url);
});
}
app.use(express.static(path.join(__dirname, 'app')));
// login/logout and linking third party providers
app.use('/auth', authRoutes);
app.use('/api', profileRoutes);
// basic crud endpoints a la tiny-server
app.use('/api/collections', crudRoutes);
/*
|--------------------------------------------------------------------------
| Start the Server
|--------------------------------------------------------------------------
*/
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});