-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (44 loc) · 1.38 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
// load our app server using express
const path = require('path')
const express = require('express')
const morgan = require('morgan')
const ejs = require('ejs')
const bodyParser = require('body-parser')
const userRouter = require('./src/routers/users')
// Database
const db = require('./src/database/mysql-db')
// Test DB
db.authenticate()
.then(() => console.log('Database connected...'))
.catch(err => console.log('Error' + err))
const app = express()
app.use(morgan('combined'))
// Define paths for Express config
const viewsPath = path.join(__dirname, '/templates/views')
const publicDirectoryPath = path.join(__dirname, '/public')
// Setup handlebars engine and views location
app.set('view engine', 'ejs')
app.set('views', viewsPath)
// Body Parser Middleware
//parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false}))
// parse apllication/json
app.use(bodyParser.json())
// Set static folder
app.use(express.static(publicDirectoryPath))
// index route
app.get('', (req, res) => {
res.render('index')
})
// Buchung route
app.get('/register', (req, res) => {
res.render('register')
})
// info route
app.get('/info', (req, res) => {
res.render('info')
})
// User routes
app.use('/users', require('./src/routers/users'))
const port = process.env.PORT || 3000
app.listen(port, console.log("Server is up and listening on port " + port))