-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (32 loc) · 1.28 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
require('./config/server');
const express = require('express'),
{ mongoose } = require('./config/mongoose'),
methodOverride = require('method-override'),
bodyParser = require('body-parser'),
expressValidator = require('express-validator'),
dateFormat = require('dateformat'),
hbs = require('hbs'),
app = express();
const indexRoutes = require('./routes/indexRoutes');
const blogRoutes = require('./routes/blogRoutes');
const port = process.env.PORT;
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(expressValidator());
app.use(methodOverride('_method'));
app.set('view engine', 'hbs');
hbs.registerPartials(__dirname + '/views/partials');
hbs.registerHelper('dateFormat', (date) => dateFormat(date, "fullDate").toUpperCase());
hbs.registerHelper('sliceBlog', (string) => {
let firstParagraph = string.indexOf('</p>');
return string.slice(0, firstParagraph) + "..";
});
app.use('/', indexRoutes);
app.use('/blog', blogRoutes);
app.use((err, req, res, next) => {
res.status(422).send({ error: err.message});
});
app.listen(port, function() {
console.log(`Server up and running on port: ${port}`);
});