@bonniernews/local-esi
Local Edge Side Includes parser
Last updated 11 days ago by jonaswalden .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bonniernews/local-esi 
SYNC missed versions from official npm registry.

Local-ESI

Build Statusdependencies Status

Make your Express app work like it had Akamai Edge Side Includes parsing or just stream your ESI decorated markup to the parser.

API

localEsi(html, req, res, next)

Use as an expressjs request callback function.

Arguments:

  • html: string with markup
  • req: request with headers and cookies
  • res: response with send, redirect, set, and status function
  • next: function to catch occasional error in
"use strict";

const localEsi = require("@bonniernews/local-esi");

module.exports = (req, res, next) => {
  res.render("index", { data: "a" }, (err, html) => {
    if (err) return next(err);

    localEsi(html, req, res, next);
  });
};

localEsi.createStream(req)

Create pipable ESI parse as stream. Emits events.

Arguments:

  • req: request with headers and cookies

Returns markup stream.

"use strict";

const {createStream} = require("@bonniernews/local-esi");

module.exports = (req, res, next) => {
  const esiParseStream = createStream(req)
    .on("add_header", (name, value) => res.set(name, value))
    .once("set_redirect", (statusCode, location) => res.redirect(statusCode, location));

  res.render("index")
    .pipe(esiParseStream)
    .on("error", next);
};

localEsi.createParser(req)

Create ESI parse transform stream. Emits events.

Arguments:

  • req: request with headers and cookies

Requires markup stream to read from. Writes object stream.

"use strict";

const HtmlParser = require("atlas-html-stream");
const {createParser: createESIParser, htmlWriter} = require("@bonniernews/local-esi");

module.exports = function channelRendering(req, res, next) {
  const esiParser = createESIParser(req)
    .once("set_redirect", (statusCode, location) => {
      res.status(statusCode).redirect(location);
    })
    .on("set_response_code", (statusCode, body) => {
      res.status(statusCode);
      if (body) res.send(body);
    })
    .on("add_header", (name, value) => {
      res.set(name, value);
    });

  return res.render("index")
    .pipe(new HtmlParser({preserveWS: true}))
    .pipe(esiParser)
    .pipe(htmlWriter())
    .pipe(res)
    .once("error", (err) => {
      next(err);
    });
};

localEsi.htmlWriter()

Returns transform object stream to markup buffer stream.

ESI Parsing Events

ESI instructions are emitted as events.

set_response_code

Set status code and optional body.

add_header

Set header name and value.

set_redirect

Redirect with status code and location.

Markup object stream

Object streams requires the schema {name, data, text} representing tag name, tag attributes, and text. This project uses atlas-html-stream for html parsing.

Current Tags

  • 1.2.2                                ...           latest (11 days ago)

50 Versions

  • 1.2.2                                ...           11 days ago
  • 1.2.1                                ...           4 months ago
  • 1.2.0                                ...           4 months ago
  • 1.1.1                                ...           5 months ago
  • 1.1.0                                ...           5 months ago
  • 1.0.3                                ...           8 months ago
  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
  • 0.14.0                                ...           8 months ago
  • 0.13.2                                ...           8 months ago
  • 0.13.1                                ...           8 months ago
  • 0.13.0                                ...           8 months ago
  • 0.12.0                                ...           10 months ago
  • 0.11.0                                ...           10 months ago
  • 0.10.2                                ...           a year ago
  • 0.10.1                                ...           a year ago
  • 0.10.0                                ...           a year ago
  • 0.9.0                                ...           a year ago
  • 0.8.3                                ...           a year ago
  • 0.8.2                                ...           a year ago
  • 0.8.1                                ...           a year ago
  • 0.8.0                                ...           a year ago
  • 0.7.5                                ...           a year ago
  • 0.7.4                                ...           a year ago
  • 0.7.3                                ...           a year ago
  • 0.7.2                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.6.2                                ...           a year ago
  • 0.6.1                                ...           a year ago
  • 0.6.0                                ...           a year ago
  • 0.5.2                                ...           a year ago
  • 0.5.1                                ...           a year ago
  • 0.5.0                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.0                                ...           a year ago
  • 0.0.8                                ...           a year ago
  • 0.0.7                                ...           a year ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 16
Last Day 0
Last Week 14
Last Month 0
Dependencies (4)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |