54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
/**
|
|
* Returns the corresponding component/function/object based on the type of instance.
|
|
* Based on the node env params, return the correct prop.
|
|
* Default is to return the ImEX Prop
|
|
* @typedef {Object} InstanceManagerObject
|
|
* @property { string | object | function } rome Return this prop if Rome.
|
|
* @property { string | object | function } promanager Return this prop if Rome.
|
|
* @property { string | object | function } imex Return this prop if Rome.
|
|
*/
|
|
|
|
function InstanceManager({ args, instance, debug, executeFunction, rome, promanager, imex }) {
|
|
let propToReturn = null;
|
|
|
|
switch (instance || process.env.INSTANCE) {
|
|
case "IMEX":
|
|
propToReturn = imex;
|
|
break;
|
|
case "ROME":
|
|
propToReturn = rome; //TODO:AIO Implement USE_IMEX
|
|
break;
|
|
case "PROMANAGER":
|
|
//Return the rome prop if USE_ROME.
|
|
//If not USE_ROME, we want to default back to the rome prop if it's undefined.
|
|
//If null, we might want to show nothing, so make sure we return null.
|
|
propToReturn = promanager === "USE_ROME" ? rome : promanager !== undefined ? promanager : rome;
|
|
break;
|
|
default:
|
|
propToReturn = imex;
|
|
break;
|
|
}
|
|
|
|
if (debug) {
|
|
console.log("InstanceRenderManager Debugger");
|
|
console.log("=========================");
|
|
console.log({ executeFunction, rome, promanager, imex, debug, propToReturn });
|
|
console.log("=========================");
|
|
}
|
|
|
|
//Checking to see if we need to default to another one.
|
|
if (propToReturn === "imex") {
|
|
propToReturn = imex;
|
|
}
|
|
if (executeFunction && typeof propToReturn === "function") return propToReturn(...args);
|
|
return propToReturn === undefined ? null : propToReturn;
|
|
}
|
|
|
|
exports.InstanceRegion = () =>
|
|
InstanceManager({
|
|
imex: "ca-central-1",
|
|
rome: "us-east-2"
|
|
});
|
|
|
|
exports.default = InstanceManager;
|