-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·56 lines (43 loc) · 1.5 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env nodejs
/* Oto Brglez - <[email protected]> - January 2017 */
let express = require('express'),
path = require('path'),
favicon = require('serve-favicon'),
morgan = require('morgan'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
_ = require('lodash');
const exphbs = require('express-handlebars');
let index = require('./routes/index');
let app = express();
// app.set('view engine', 'haml');
// app.engine('.haml', require('hamljs').renderFile);
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
// app.set('views', path.join(__dirname, 'views'));
app.use(morgan('combined'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('node-sass-middleware')({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public'),
indentedSyntax: true,
sourceMap: true
}));
app.use(express.static(path.join(__dirname, 'public')));
app.use(index);
app.use((req, res, next) =>{
let err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.json({'error': err.message});
});
const port = _.parseInt(process.env.PORT || '8877',10);
app.listen(port, ()=> console.log(`ivo is up on ${port}.`));
module.exports = app;