Express middleware that handles SPF requests
npm install spf-expressFramework documentation can be found here
npm install spf-express
`To run tests:
`
npm test
`$3
`javascript
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
- 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.
$3
#### Simple example
`javascript
var spf_express = require("spf-express"),
express = require("express"),
app = express()app.use(spf_express({
paths: {
"/sample_path": {
title: "My website title",
body: "
Hello World!
"
} //SPF response object
}
}))
`
More on SPF response objects here#### Advanced example
`javascript
app.use(spf_express({
paths: {
"/sample_path": function(req, res, next) { //express middleware function
res.json({
title: "My website title",
body: "Hello World!
"
})
}
},
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
``