Getting different web3 instances in cloud code

I have the following cloud code function to return stats about the latest block. When the cId is mainnet (0x1) the function returns fine, but when it is another chain (0x4, 0x3 etc) there is this error: Error: Could not find provider. This used to work on an older version of the dapp I am building (different server also). Am I doing something wrong with the new version (the cloud code was copy and pasted)? Any tips are greatly appreciated.

Moralis.Cloud.define(“getNetworkStats”, async function (request) {

let cId = request.params.cId;
let block = 0;
let avgGas = 0;

if(!cId == null || !cId == 0){
const web3 = Moralis.web3ByChain(cId);
block = await web3.eth.getBlockNumber();
avgGas = await web3.eth.getGasPrice();
avgGas = web3.utils.fromWei(avgGas, “gwei”)

let response = [block, avgGas];
return response;

You can find example in documentation how to use web3 with a custom RPC url where you can use the speedy node. The syntax that you use works only for the chains that are enameled for your server.

I fixed it by enabling them on the server. Is there a way to enable testnets and mainnets to the server?

No, a server is only for mainnet or testnet. You can use the alternative that I described, it works with any chain where you have a RPC url

Ah gotcha thank you so much again