You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
594 B
32 lines
594 B
3 years ago
|
'use strict'
|
||
|
|
||
|
const { promisify } = require('util')
|
||
|
const sleep = promisify(setTimeout)
|
||
|
const templates = 'templates'
|
||
|
|
||
|
const fastify = require('fastify')({
|
||
|
logger: true
|
||
|
})
|
||
|
|
||
|
fastify.register(require('.'), {
|
||
|
engine: {
|
||
|
nunjucks: require('nunjucks')
|
||
|
},
|
||
|
templates
|
||
|
})
|
||
|
|
||
|
async function something () {
|
||
|
await sleep(1000)
|
||
|
return new Date()
|
||
|
}
|
||
|
|
||
|
fastify.get('/', async (req, reply) => {
|
||
|
const t = await something()
|
||
|
return reply.view('/index.njk', { text: t })
|
||
|
})
|
||
|
|
||
|
fastify.listen(3000, err => {
|
||
|
if (err) throw err
|
||
|
console.log(`server listening on ${fastify.server.address().port}`)
|
||
|
})
|