cube.js 配置自定义basePath 扩展cube.js 多租户处理

cube.js 默认的basePath是cubejs-api 我们可以通过配置自定义的basePath提升多租户的处理能力

参考配置

module.exports = {
    basePath:"/oneservice/:projectid",
    schemaVersion: ({ securityContext }) => {
        console.log(securityContext)
    },
    // 基于extendContext 扩展securityContext 可以扩展请求
    extendContext:(req)=>{
        console.log("projectid:",req.params.projectid)
        if (req.securityContext){
            req.securityContext.projectid=req.params.projectid
        }
    }
};

参考请求格式

curl --location --request GET 'http://localhost:4000/oneservice/002/v1/load?query=%7B%22measures%22%3A%5B%22Demoapps.count%22%5D%2C%22timeDimensions%22%3A%5B%5D%2C%22order%22%3A%7B%22Demoapps.count%22%3A%22desc%22%7D%2C%22dimensions%22%3A%5B%22Demoapps.name%22%5D%7D&queryType=multi' 
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTgxNDUxODEsImV4cCI6MTYxODIzMTU4MX0.mHfHkmdQ3HMjaVrjMjbSq0eOPlnrQKQwllQ_BYlsU_E'

运行参考格式

说明

因为cube.js 的basePath 也是使用了express 框架的能力,所以我们可以方便的进行扩展,这样我们系统的多租户能力就更加方便了

参考资料

https://expressjs.com/en/guide/routing.html
https://cube.dev/docs/config#options-reference-base-path

原文地址:https://www.cnblogs.com/rongfengliang/p/14645468.html