ExpressJS middleware
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.
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");
});
Check if all the mandatory headers are set, otherwise it will throw an authentication error(401).
Mandatory headers are:
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";
}
}
Modify the key bypassheaders
within the headers.json
.