Answers for "fastify point-of-view"

0

fastify point-of-view

//BASIC TEMPLATE

const fastify = require('fastify')()

fastify.register(require('point-of-view'), {
  engine: {
    ejs: require('ejs')
  }
})

fastify.get('/', (req, reply) => {
  reply.view('/templates/index.ejs', { text: 'text' })
})

// With async handler be sure to return the result of reply.view
fastify.get('/', async (req, reply) => {
  const t = await something()
  return reply.view('/templates/index.ejs', { text: 'text' })
})

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})
Posted by: Guest on March-09-2021

Browse Popular Code Answers by Language