se

spf-express

Express middleware that handles SPF requests

Showing:

Popularity

Downloads/wk

1

GitHub Stars

14

Maintenance

Last Commit

5yrs ago

Contributors

3

Package

Dependencies

0

Size (min+gzip)

0.6KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

spf-express npm

Express middleware for youtube's SPF framework.

Framework documentation can be found here

Features

  • Intercept requests with custom SPF query identifiers
  • Attach SPF response objects or custom express handler to desired path

Installation

npm install spf-express

To run tests:

npm test

API

spf_express(opts)   //returns an express middleware function

Options:

  • paths: Object
    • [path: String]: Object | Function
    • Key value can either be a SPF response object or an express middleware function (supports URL params)
    • Will return the corresponding response object or forward request to middleware when a SPF request is sent to a defined path.
  • identifiers: [String]
    • default: ["navigate", "prefetch", "navigate-back"]
    • Extends on the default valid SPF request identifiers on the "spf" query field
      • if the "spf" query field in a request contains a value in this field, it will be treated as a valid SPF request.
  • override: Boolean
    • default: False
    • will override default list of SPF request identifiers with those set in the "identifiers" field if set to True.

Examples

Simple example

var spf_express = require("spf-express"),
    express = require("express"),
    app = express()

app.use(spf_express({
    paths: {
        "/sample_path": {
            title: "My website title",
            body: "<h1>Hello World!</h1>"
        } //SPF response object
    }
}))

More on SPF response objects here

Advanced example

app.use(spf_express({
    paths: {
        "/sample_path": function(req, res, next) { //express middleware function
            res.json({
                title: "My website title",
                body: "<h1>Hello World!</h1>"
            })
        }   
    },
    identifiers: ["my_identifier"],
    override: true   //"my_identifier" is now the only valid SPF request identifier!
}))

Example project

$ git clone https://github.com/Arthelon/spf-express.git
$ cd spf-express
$ npm install --dev
$ npm run start-example

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100