forked from sushmakaluva/goAds.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·43 lines (33 loc) · 1.09 KB
/
server.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
const express = require('express');
const exphbs = require('express-handlebars');
const db = require('./models');
// Sets up the Express App
// =============================================================
const app = express();
const PORT = process.env.PORT || 7500;
// Sets up the Express app to handle data parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Static directory
app.use(express.static('public'));
// Set Handlebars as the default templating engine.
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
// register new helper function
var hbs = exphbs.create({});
hbs.handlebars.registerHelper('sum', function (cartItems) {
let s = 0;
for (let i = 0; i < cartItems.length; i++) {
s += cartItems[i].price;
}
return s;
})
// Routes
// =============================================================
require('./routes/api-routes.js')(app);
require('./routes/html-routes.js')(app);
db.sequelize.sync({}).then(() => {
app.listen(PORT, () => {
console.log(`App listening on PORT ${PORT}`);
});
});