-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
39 lines (33 loc) · 828 Bytes
/
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
'use strict'
const path = require('path')
const fastify = require('fastify')({
logger: {
prettyPrint: true
}
})
const port = process.env.PORT || 3000
fastify.register(require('point-of-view'), {
engine: {
handlebars: require('handlebars')
}
})
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'public'),
prefix: '/public/'
})
// Challenge: NO SCHEMA????
// Please add a schema to validate the following properties from query string:
// - name
// - course (required)
fastify.get('/', (request, reply) => {
const name = request.query.name || 'Anonymous'
const course = request.query.course
reply.view('/templates/index.hbs', { name, course })
})
async function start () {
await fastify.listen(port)
}
start().catch(err => {
fastify.log.error(err)
process.exit(1)
})