cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Multitenancy Streamline mtxs - How to add custom mtx hook?

iashishsingh
Participant
0 Kudos

Hello,

With @sap/cds-mtx, to add any custom hooks to the server, we used to do following:


const cds = require("@sap/cds");
const middleware = require("./middleware");
cds.env.features.fetch_csrf = true;
cds.on("bootstrap", async (app) => {
// middlewares for mtx
cds.mtx.in(app).then(async () => {
// bind middlewares app.use("/middleware", middleware);
const provisioning = await cds.connect.to("ProvisioningService");
provisioning.impl(require("./provisioning"));
});

}); module.exports = cds.server;

With cds-mtxs, cds.mtx is no longer a valid object. How should we add custom middlewares in this case?

Thanks,

Ashish

View Entire Topic
iashishsingh
Participant
0 Kudos

The updated section:


// Update Guide

// https://cap.cloud.sap/docs/guides/multitenancy/mtxs#adding-custom-lifecycle-event-handlers

cds.on("served", async (app) => {  

// middlewares for mtx  

// bind middlewares  

// app.use("/middleware", middleware);  

// provide SAP BTP dependencies  

// https://cap.cloud.sap/docs/guides/deployment/as-saas#sap-btp-dependencies  

require("./dependencies")(cds);  

const provisioning = await cds.connect.to("cds.xt.SaasProvisioningService");  

provisioning.impl(require("./provisioning"));

});