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 - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

1

index.js

@@ -33,3 +33,2 @@ "use strict";

if (!completed) res.send(parsed);
// return next && next(null, parsed);
});

@@ -36,0 +35,0 @@ }

10

package.json
{
"name": "@bonniernews/local-esi",
"version": "1.0.0",
"version": "1.0.1",
"description": "Local Edge Side Includes parser",

@@ -10,3 +10,4 @@ "main": "index.js",

"keywords": [
"esi"
"esi",
"stream"
],

@@ -25,3 +26,3 @@ "author": "Bonnier News",

"pump": "^3.0.0",
"pumpify": "^2.0.0",
"pumpify": "^2.0.1",
"request": "^2.88.0"

@@ -38,4 +39,3 @@ },

"lib/",
"index.js",
"LICENSE"
"index.js"
],

@@ -42,0 +42,0 @@ "bugs": {

@@ -6,11 +6,21 @@ Local-ESI

Make your Express app work like it had Akamai Edge Side Includes parsing.
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(req, res[, callback])`: returns ESI evaluated markup in callback or as promised
- `localEsi.createStream(req)`: returns pipable object stream with ESI evaluated content
- [`localEsi(html, req, res, next)`](#localesihtml-req-res-next)
- [`localEsi.createStream(req)`](#localesicreatestreamreq)
- [`localEsi.createParser(req)`](#localesicreateparserreq)
- [`localEsi.htmlWriter()`](#localesihtmlwriter)
## `localEsi(req, res[, callback])`
## `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
```javascript

@@ -30,25 +40,88 @@ "use strict";

## `localEsi.createStream(req[, res])`
## `localEsi.createStream(req)`
Used as object stream.
Create pipable ESI parse as stream. Emits [events](#esi-parsing-events).
Arguments:
- `req`: request with headers and cookies
Returns markup stream.
```javascript
"use strict";
const localEsi = require("@bonniernews/local-esi");
const {createStream} = require("@bonniernews/local-esi");
module.exports = (req, res, next) => {
const esiPipeline = localEsi.createStream(req);
res.render("index", { data: "a" })
.pipe(esiPipeline)
.on("error", next)
.on("set_redirect", (statusCode, location) => res.redirect(statusCode, location));
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);
};
```
## Events
## `localEsi.createParser(req)`
- `error`: an error occured
- `set_response_code`: send status code and optional body
- `add_header`: set header name and value
- `set_redirect`: redirect with status code and location
Create ESI parse transform stream. Emits [events](#esi-parsing-events).
Arguments:
- `req`: request with headers and cookies
Requires [markup stream](#markup-object-stream) to read from. Writes object stream.
```javascript
"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](#markup-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](https://www.npmjs.com/package/atlas-html-stream) for html parsing.
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