-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (48 loc) · 1.67 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
61
62
63
64
const express = require('express'),
http = require('http'),
favicon = require('serve-favicon'),
bodyParser = require('body-parser'),
config = require('./config/config'),
pageRoutes = require("./src/page-routes"),
restRoutes = require("./src/rest-routes"),
AboutUsService = require('./src/models/aboutUs/service'),
log = require('./lib/log')(module),
errorHandler = require('express-error-handler'),
path = require('path');
const app = express();
let aboutUs = [];
AboutUsService.getAboutUsFromContentful('aboutUs', (aboutUs) => {
this.aboutUs = aboutUs
});
app.set('port', config.port);
http.createServer(app).listen(app.get('port'), () => {
log.info('Express server listening on port ' + app.get('port'));
});
app.set('views', __dirname + '/assets/templates');
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/assets/public/'));
app.use(favicon(path.join(__dirname, '/assets/public/img', 'favicon.ico')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ type: 'application/*+json' }));
app.use(bodyParser.json());
app.get('/', (req, res, next) => {
res.render("index", {
aboutUs: this.aboutUs
})
});
app.post('/api/update', (req, res, next) => {
AboutUsService.getAboutUsFromContentful('aboutUs', (aboutUs) => {
this.aboutUs = aboutUs;
res.redirect('/');
});
});
app.use(pageRoutes);
app.use(restRoutes);
// app.use((err, req, res, next) => {
// // NODE_ENV = 'production'
// if (app.get('env') === 'development') {
// app.use(errorHandler());
// } else {
// res.send(500);
// }
// });