forked from techx/quill
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
58 lines (39 loc) · 1.48 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
// 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 compression = require('compression')
var sslRedirect = require('heroku-ssl-redirect');
var mongoose = require('mongoose');
var port = process.env.PORT || 3000;
var database = process.env.DATABASE || process.env.MONGODB_URI || "mongodb://localhost:27017";
var settingsConfig = require('./config/settings');
var adminConfig = require('./config/admin');
var app = express();
// enable ssl redirect
app.use(sslRedirect());
// Connect to mongodb
mongoose.set('useCreateIndex', true);
mongoose.connect(database, { useNewUrlParser: true , useUnifiedTopology: true });
app.use(morgan('dev'));
app.use(compression());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
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);