-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
97 lines (76 loc) · 2.16 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const path = require('path')
const express = require('express')
const prismicH = require('@prismicio/helpers')
const client = require('./config/prismicConfig.js')
const app = express()
const port = process.env.PORT || 3000
app.set('view engine', 'pug')
app.set('views', path.join(__dirname, 'views'))
app.use(express.static(path.join(__dirname + '/dist')))
app.use((req, res, next) => {
res.locals.ctx = {
prismicH,
}
next()
})
const requestHandler = async () => {
const metadata = await client.getSingle('metadata')
const navigation = await client.getSingle('navigation')
const contact = await client.getSingle('contact')
const footer = await client.getSingle('footer')
return {
meta: metadata.data,
navigation: navigation.data,
contact: contact.data,
footer: footer.data,
}
}
app.get('/', async (req, res) => {
const initial = await requestHandler()
const home = await client.getSingle('home')
res.render('pages/home', {
home: home.data,
...initial,
})
})
app.get('/about', async (req, res) => {
const initial = await requestHandler()
const about = await client.getSingle('about')
res.render('pages/about', {
about: about.data,
...initial,
})
})
app.get('/projects', async (req, res) => {
const initial = await requestHandler()
const projects = await client.getAllByType('project')
res.render('pages/projects', {
projects,
...initial,
})
})
app.get('/projects/:uid', async (req, res) => {
const initial = await requestHandler()
const project = await client.getByUID('project', req.params.uid)
res.render('pages/detail', {
project: project.data,
...initial,
})
})
app.get('/contact', async (req, res) => {
const initial = await requestHandler()
const contact = await client.getSingle('contact')
res.render('pages/contact', {
contact: contact.data,
...initial,
})
})
app.get('*', async (req, res) => {
const initial = await requestHandler()
res.render('pages/404', {
...initial,
})
})
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`)
})