-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (32 loc) · 1.43 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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const exphbs = require('express-handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');
const Handlebars = require('handlebars');
// Database
const db = require('./config/database');
// test DB
db.authenticate()
.then(() => console.log('Database Connection established'))
.catch(err => console.log('Error connecting' + err))
const app = express();
// Handlebars configuration (engine is mainly for interface)
// layout is the thing that stores everything that is represented on the webpage
// express handlebars takes obj as arguments and callling it as a main. handlebars
app.engine('.handlebars', exphbs({ handlebars: allowInsecurePrototypeAccess(Handlebars), defaultLayout: 'main' }));
// setting view engine to handlebars
app.set('view engine', 'handlebars');
// body parser
app.use(bodyParser.urlencoded({ extended: false }));
// set static folder
app.use(express.static(path.join(__dirname, 'public')));
// rendering index handlebars +
// choosing the different layout than defaultLayout. i.e. landing
app.get('/', (req, res) => {
res.render('index', { layout: 'landing' });
})
// GIG routes
app.use('/gigs', require('./routes/gigs'))
const PORT = process.env.PORT || 5000;
app.listen(PORT, console.log(`Server started at ${PORT}`));