Skip to content

Instantly share code, notes, and snippets.

@gx0r
Created January 20, 2016 16:20
Show Gist options
  • Save gx0r/7b414a2377bb7e804d7d to your computer and use it in GitHub Desktop.
Save gx0r/7b414a2377bb7e804d7d to your computer and use it in GitHub Desktop.
Koa rendering template
const jade = require('jade')
app.use((req, res) => {
const locals = req.locals // get your template locals from where ever
locals.cache = process.env.NODE_ENV === 'production' // set the template cache
const html = jade.renderFile('templates/home.jade', locals) // render the template
res.setHeader('Content-Length', Buffer.byteLength(html))
res.setHeader('Content-Type', 'text/html; charset=utf-8') // set the content type header
res.end(html) // send the response
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment