Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 2.04 KB

README.md

File metadata and controls

79 lines (60 loc) · 2.04 KB

restify-render-middleware

Another middleware to render pages with restify. Inspired by restify-render

travis Code Coverage npm

Installation:

npm i restify-render-middleware -S

Note:

Requires Node >8.0.0.

Example:

This example is available here as well.

'use strict'

const restify = require('restify')
const render = require('restify-render-middleware')

const server = restify.createServer()
server.use(render({
  engine: 'pug',
  dir: __dirname
}))

server.get('/:name', function (req, res) {
  res.render('view.pug', { name: req.params.name || 'nameless' })
})

server.listen(8080, function () {
  console.log('listening on :8080, curl /:name')
})

NOTE: if you need another engine to render the view, simply install

npm install swig-templates

To use you must configure an object

server.use(render({
  engine: {
    name: 'swig',
    extname: 'html'
  },
  dir: __dirname
}))

server.get('/:name', function (req, res) {
  res.render('view', { name: req.params.name || 'nameless' })
})

In this case you do not need to configure the extension to viewer. For a list of supported engines go to the link.

Tests

npm test

License

MIT

Copyright (c) 2018-present