forked from techx/quill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (49 loc) · 1.79 KB
/
app.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
60
61
62
63
64
// Load the dotfiles.
require('dotenv').load({silent: true});
var express = require('express');
// Middleware!
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var mongoose = require('mongoose');
var port = process.env.PORT || 3000;
var database = process.env.DATABASE || process.env.MONGODB_URI || "mongodb://localhost:27017";
mongoose.Promise = Promise;
var settingsConfig = require('./config/settings');
var adminConfig = require('./config/admin');
var app = express();
// Connect to mongodb
mongoose.connect(database, {
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
});
app.use(morgan('dev'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
if(process.env.NODE_ENV === 'production'){
app.use(function(req, res, next) {
// The 'x-forwarded-proto' check is for Heroku
if (!req.secure && req.get('x-forwarded-proto') !== 'https' && process.env.NODE_ENV !== "dev") {
// return res.redirect('https://' + req.get('host') + req.url);
}
next();
})
}
app.use(express.static(__dirname + '/app/client'));
// Routers =====================================================================
var apiRouter = express.Router();
require('./app/server/routes/api')(apiRouter);
app.use('/api', apiRouter);
var authRouter = express.Router();
require('./app/server/routes/auth')(authRouter);
app.use('/auth', authRouter);
require('./app/server/routes')(app);
// listen (start app with node server.js) ======================================
app.listen(port);
console.log("App listening on port " + port);