Migrating our existing Nodes API backend to Azure serverless Functions, we have custom Express middleware implementation, for example typical router-middleware-controller
Router:
const mdw = require("../middleware/mdw");
module.exports = app =>
{
const controller = require("../controller/mycontroller");
app.post("/getmyprofile", mdw.ValidateSession, controller.GetMyProfile);
};
mdw:
const decode = require("jwt-decode");
const objPS = require("../DataModel/PostgreSql");
async function ValidateSession(req, res, next)
{
theToken = req.headers["authorization"].toString().split(' ')[1];
vuniqueid = decode(theToken).sub; //decode and extract an unique ID from Header
var vsessionid = req.cookies.MySessionID; // SessionID from cookie
var params = {sid: vsessionid, uid: vuniqueid}; // to be sent to DB for further check
objPS.GetSession(params, (bad, good) =>
{
if (bad) {res.status401).send();}
else
{
res.locals.GoodSession = {...}; // pass this new obj for controller.GetMyProfile above
next();
}
}
});
According to MS Shifting from Express.js to Azure Functions
Many middleware modules are no longer required in light of Azure Functions and Azure API Management capabilities. Ensure you can replicate or replace any logic handled by essential middleware before migrating endpoints.
Well, it offers no sample or guidelines on how to. So where can I find info on how to?