🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

server-render

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-render

HTML server rendering middleware

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

server-render stability

npm version build status test coverage downloads js-standard-style

HTML server rendering middleware. Detects if an incoming request is requesting text/html and calls a function to render the corresponding response.

Usage

Assuming the client is a choo app:

const render = require('server-render')
const merry = require('merry')
const client = require('./client')

const app = merry()
app.use(render((route) => client.toString(route)))
app.start()

Caching

Sometimes you know the paths you're going to render up front, and want to cache them in a Node buffer so the reponse times are as fast as they can be.

const cache = require('server-render/cache')
const render = require('server-render')
const merry = require('merry')
const client = require('./client')

const routes = {
  default: '/404',
  routes: [ '/', '/bar', '/bar/baz', '/bar/:foobar' ]
}

const app = merry()
app.use(cache(routes, (route) => client.toString(route)))
app.start()

API

middleware = render(handler(route))

Create a new render function that takes a callback and returns a middleware function. The callback should return a string synchronously. The middleware function has the signature of (req, res, next).

middleware = cache(routes, handler(route))

Cache routes into Node buffers. Takes an object containing a .routes array of routes, and a .default value for the default route to match if no other routes could be matched.

Installation

$ npm install server-render

See Also

License

MIT

Keywords

render

FAQs

Package last updated on 11 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts