Skip to content

Commit

Permalink
build: use express-handlebars as view engine
Browse files Browse the repository at this point in the history
  • Loading branch information
klkuoguru committed Mar 26, 2023
1 parent d07d3ea commit b355f79
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const express = require('express')
const { engine } = require('express-handlebars')
const app = express()
const port = 3000

app.engine('.hbs', engine({extname: '.hbs'}))
app.set('view engine', '.hbs')
app.set('views', './views')
app.use(express.static('public'))

app.get('/', (req, res) => {
res.redirect('/movies')
})

app.get('/movies', (req, res) => {
res.send('listing movies')
res.render('index')
})

app.get('/movie/:id', (req, res) => {
Expand Down
159 changes: 158 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author": "klkuo",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
"express": "^4.18.2",
"express-handlebars": "^7.0.4"
}
}
1 change: 1 addition & 0 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Example App: Home</h1>
12 changes: 12 additions & 0 deletions views/layouts/main.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example App</title>
</head>
<body>

{{{body}}}

</body>
</html>

0 comments on commit b355f79

Please sign in to comment.