-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (46 loc) · 1.42 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
const express = require('express');
const mustache = require('mustache');
const mustacheExpress = require('mustache-express');
const session = require('express-session');
const bodyParser = require('body-parser');
const routes = require('./routes');
// mongoose
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const environment = process.env.NODE_ENV || "development";
let mongoURL;
if (environment === "production") {
mongoURL = process.env.MONGODB_URI;
} else {
mongoURL = require("./config.json")[environment].mongoURL;
}
mongoose.connect(mongoURL);
// models
const Snippets = require('./models/snippets');
const Users = require('./models/users');
// controllers
const createController = require('./controllers/create');
const detailController = require('./controllers/detail');
const indexController = require('./controllers/index');
const welcomeController = require('./controllers/welcome');
// express
const app = express();
// mustache
app.engine('mustache', mustacheExpress());
app.set('view engine', 'mustache');
// views
app.set('views', './views');
// body parser
app.use(bodyParser.json());
app.use((bodyParser.urlencoded({extended: false})));
// session
app.use(session({
secret: 'Covfefe'
, resave: false
, saveUninitialized: false
}));
routes(app);
app.listen(process.env.PORT || 3000, () => {
console.log('Successfully started express application');
});
module.exports = app;