Created
January 20, 2016 16:20
-
-
Save gx0r/7b414a2377bb7e804d7d to your computer and use it in GitHub Desktop.
Koa rendering template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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