Skip to content

Commit 5134791

Browse files
brijeshgajjarfyndpooransuthar1999
authored andcommitted
Multicluster support changes and cluster origin added
1 parent 55d36d9 commit 5134791

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

express/api_routes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ function setupProxyRoutes(extension) {
99
const apiRoutes = express.Router({ mergeParams: true });
1010
const applicationProxyRoutes = express.Router({ mergeParams: true });
1111

12-
applicationProxyRoutes.use(["/:cluster_id", "/"],async (req, res, next) => {
12+
applicationProxyRoutes.use( "/" ,async (req, res, next) => {
1313
try {
14-
const clusterId = req.params.cluster_id;
14+
const clusterId = req.query.cluster_origin;
1515
if (clusterId) {
1616
extension = ExtensionFactory.getExtension(clusterId)
1717
}
@@ -34,9 +34,9 @@ function setupProxyRoutes(extension) {
3434
}
3535
});
3636

37-
apiRoutes.use(["/:cluster_id", "/"], sessionMiddleware(extension, true), async (req, res, next) => {
37+
apiRoutes.use( "/" , sessionMiddleware(extension, true), async (req, res, next) => {
3838
try {
39-
const clusterId = req.params.cluster_id;
39+
const clusterId = req.query.cluster_origin;
4040
if (clusterId) {
4141
extension = ExtensionFactory.getExtension(clusterId)
4242
}

express/extension_factory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ExtensionFactory {
88
static getExtension(clusterId) {
99
const clusterExt = ExtensionFactory._extensionMap[clusterId]
1010
if (clusterId !== null && !clusterExt) {
11-
throw FdkInvalidCluster(`Extension instance not found for clusterId ${clusterId}`);
11+
throw new FdkInvalidCluster(`Extension instance not found for clusterId ${clusterId}`);
1212
}
1313
return clusterExt;
1414
}
@@ -27,7 +27,8 @@ class ExtensionFactory {
2727
if (!ExtensionFactory._defaultExt) {
2828
ExtensionFactory._defaultExt = extInstance;
2929
}
30-
ExtensionFactory._extensionMap[extConfig.cluster_id] = extInstance;
30+
const cluster_id = clusterId || extConfig.cluster.replace("https://", "").replace("http://", "");
31+
ExtensionFactory._extensionMap[cluster_id] = extInstance;
3132
promises.push(extInstance.initialize(extConfig))
3233
}
3334
return Promise.all(promises);

express/middleware/session_middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { SESSION_COOKIE_NAME } = require('./../constants');
55
function sessionMiddleware(extension, strict) {
66
return async (req, res, next) => {
77
try {
8-
const clusterId = req.params.cluster_id;
8+
const clusterId = req.query.cluster_origin;
99
if (clusterId) {
1010
extension = ExtensionFactory.getExtension(clusterId)
1111
}

express/routes.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const FdkRoutes = express.Router();
1212

1313
function setupRoutes(ext) {
1414

15-
FdkRoutes.get(["/:cluster_id/fp/install", "/fp/install"], async (req, res, next) => {
15+
FdkRoutes.get("/fp/install", async (req, res, next) => {
1616
// ?company_id=1&client_id=123313112122
1717
try {
18-
const cluster_id = req.params.cluster_id;
18+
const cluster_id = req.query.cluster_origin;
1919
if (cluster_id) {
2020
ext = ExtensionFactory.getExtension(cluster_id)
2121
}
@@ -91,10 +91,10 @@ function setupRoutes(ext) {
9191
}
9292
});
9393

94-
FdkRoutes.get(["/:cluster_id/fp/auth", "/fp/auth"], sessionMiddleware(ext, false), async (req, res, next) => {
94+
FdkRoutes.get("/fp/auth", sessionMiddleware(ext, false), async (req, res, next) => {
9595
// ?code=ddjfhdsjfsfh&client_id=jsfnsajfhkasf&company_id=1&state=jashoh
9696
try {
97-
const cluster_id = req.params.cluster_id;
97+
const cluster_id = req.query.cluster_origin;
9898
if (cluster_id) {
9999
ext = ExtensionFactory.getExtension(cluster_id)
100100
}
@@ -173,11 +173,11 @@ function setupRoutes(ext) {
173173
});
174174

175175

176-
FdkRoutes.post(["/:cluster_id/fp/auto_install", "/fp/auto_install"], sessionMiddleware(ext, false), async (req, res, next) => {
176+
FdkRoutes.post("/fp/auto_install", sessionMiddleware(ext, false), async (req, res, next) => {
177177
try {
178178

179179
let { company_id, code } = req.body;
180-
const cluster_id = req.params.cluster_id;
180+
const cluster_id = req.query.cluster_origin;
181181
if (cluster_id) {
182182
ext = ExtensionFactory.getExtension(cluster_id)
183183
}
@@ -227,10 +227,13 @@ function setupRoutes(ext) {
227227
}
228228
});
229229

230-
FdkRoutes.post(["/:cluster_id/fp/uninstall", "/fp/uninstall"], async (req, res, next) => {
230+
FdkRoutes.post("/fp/uninstall", async (req, res, next) => {
231231
try {
232232
let { company_id } = req.body;
233-
const cluster_id = req.params.cluster_id;
233+
const cluster_id = req.query.cluster_origin;
234+
if (cluster_id) {
235+
ext = ExtensionFactory.getExtension(cluster_id)
236+
}
234237
let sid;
235238
if (!ext.isOnlineAccessMode()) {
236239
sid = Session.generateSessionId(false, {

express/webhook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class WebhookRegistry {
291291
}
292292
try {
293293
const { body } = req;
294-
const clusterId = req.params.cluster_id;
294+
const clusterId = body.referer || req.query.cluster_origin;
295295
if (body.event.name === TEST_WEBHOOK_EVENT_NAME) {
296296
return;
297297
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)