-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
51 lines (38 loc) · 1.38 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
'use strict';
const fs = require('fs');
const path = require('path');
const express = require('express');
const logger = require('morgan');
const hbs = require('hbs');
const layouts = require('handlebars-layouts');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
const mongo = require('./middleware/mongoConnect');
const cookieAuthenticator = require('./middleware/cookieAuthenticator');
const renderLayout = require('./middleware/renderLayout');
// view engine setup
app.set('views', path.join(__dirname, 'pages'));
app.set('view engine', 'hbs');
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(express.static(path.join(__dirname, 'public')));
app.use((req, res, next) => {
req.commonData = {
isDev: process.env.NODE_ENV !== 'production'
};
next();
});
app.use(renderLayout());
app.use(mongo());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(cookieAuthenticator());
require('./routes')(app);
hbs.registerPartials(path.join(__dirname, 'blocks'));
hbs.handlebars.registerHelper(layouts(hbs.handlebars));
hbs.handlebars.registerPartial('base', fs.readFileSync('./pages/base/base.hbs', 'utf8'));
module.exports.hbs = hbs;
module.exports = app;