sdk-middleware-base v0.2.0
ANSC Middleware
ExpressJS middleware
What does it do?
It bypasses any header starting with x-aeg-
or x-att
. It also generates a header for transaction ID if
it has not been set.
Usage
Install it:
npm install -S sdk-javascript-middleware
Declare it and use it
var anscmid = require("sdk-middleware-base");
// Assuming 'app' is an express object
app.use(anscmid());
Full example:
'use strict';
var express = require("express"),
app = express(),
anscmid = require("sdk-middleware-base");
app.get("/", function(req, res){
res.send("hello world");
});
app.listen(8080, function(){
console.log("app started");
});
Options
enforceHeaders (boolean, default true)
Check if all the mandatory headers are set, otherwise it will throw an authentication error(401).
Mandatory headers are:
Developer Notes
Adding more headers automatically
Adding logic to auto generate new headers can be done within the object aux
(index.js). The property "toGenerate" contains the map for headers and the generators. For instance, if you wanted to add a custom header with current time, you could
modify the object like this
toGenerate: {
"x-current-time": function(){
return new Date();
}
}
The object aux
will discover this header automatically and add the corresponding header without further change, you can also specify constants like this:
toGenerate: {
"x-sdk-name": function(){
return "nodejs";
}
}
Adding/removing more prefixes that will be bypassed
Modify the key bypassheaders
within the headers.json
.
8 years ago