-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·40 lines (37 loc) · 1.25 KB
/
index.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
const express = require('express');
const app = express();
const { port, dbURI, secret } = require('./config/environment');
const expressLayouts = require('express-ejs-layouts');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
const session = require('express-session');
const flash = require('express-flash');
const userAuth = require('./lib/userAuth');
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect(dbURI, { useMongoClient: true });
const routes = require('./config/routes');
//settings
app.set('view engine', 'ejs');
app.set('views', `${__dirname}/views`);
//middleware
app.use(express.static(`${__dirname}/public`));
app.use(expressLayouts);
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride(req => {
if(req.body && typeof req.body === 'object' && '_method' in req.body) {
const method = req.body._method;
delete req.body._method;
return method;
}
}));
app.use(session({
secret: secret,
resave: false,
saveUninitialized: false
}));
app.use(flash());
app.use(userAuth);
// ======================================================================
app.use(routes);
app.listen(port, () => console.log(`Express is listening on port ${port}`));