Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bonniernews/local-esi

Package Overview
Dependencies
Maintainers
6
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bonniernews/local-esi

Local Edge Side Includes parser

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-88%
Maintainers
6
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 03 Oct 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc