express-template-stream
Last updated 2 years ago by luigiplr .
MIT · Original npm · Tarball · package.json
$ cnpm install express-template-stream 
SYNC missed versions from official npm registry.

express-template-stream [README IS WIP]

NPM version Dependency Status npm

Express middleware that allows streaming of template literals w/ interpolation of Node.JS streams, Arrays and Promises.

Installation

$ npm install express-template-stream --save

API

ETS.middleware([options])

Creates a new Express Template Stream middleware instance.

Arguments

  • [options] (Object) :
    • [debug] (Boolean): Defaults to false. If true all requests will have an x-ets-streamed header added. Its value being a binary 1 or 0 depending on if the request was streamed or not. Also sets this.debug within StreamTemplate Instances.
    • [minify] (Boolean): Defaults to true. Minify HTML
    • [templates] (Object): Consisting of all the possible StreamTemplates that can be used.
    • [headers] (Function|Object): Headers to be added to every request regardless of the StreamTemplate used. (Function must return an object)
    • [match] (Function): Expects an object returned with the shape of { templateKey: string, templateData: any } templateData can be accessed via this.data within StreamTemplates Instances.

Examples

Create a new middleware instance
export default ETS.middleware({
  debug: process.env.NODE_ENV === 'development',
  minify: process.env.NODE_ENV === 'production',
  headers: (req, res) => {
    return {
      ...ETS.defaultHeaders,
      'x-server-hash': ...
    }
  },
  templates: {
    amp: // AMP specific render template
    normal: // render template
    bot: // bot specific render template
  },
  match: (req, res) => {
    return {
      templateKey: req.useragent.includes('bot') ? 'bot' : 'normal',
      templateData: {
        ...
      }
    }
  }
})

Current Tags

  • 0.0.1                                ...           latest (2 years ago)

1 Versions

  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |