Unable to call function, getting html as response

I have created a simple cloud function on moralis to fetch and store currency rates for a given currency code:

const axios = require("axios");
const { allowed_currencies } = require("../functions/constans/other");
const create_api_message = require("../functions/methods/other/create_api_message");
const { openexchangerates: { API_key } } = require("../functions/config");

Moralis.Cloud.define("get_rates_for_currency", async ({ params: { currency }}) => {
  const five_days_miliseconds = 4.32e+8
  try {
    // For better caching
    const rates = Moralis.Object.extend("currency_rates");
    const currency_rates = new Moralis.Query(rates)
    // Check if rates exist and they are max 5 days old
    if (
      currency_rates &&
      currency_rates[currency] &&
      (Date.now() - (currency_rates[currency].timestamp * 1000)) < five_days_miliseconds
    ) return currency_rates[currency] // Send cached rates

    const { data } = await axios.get(`https://openexchangerates.org/api/latest.json?app_id=${
    const rates_info = { rates: data.rates, timestamp: data.timestamp, base: data.base }
    const updated_rates = new rates();

    updated_rates.set(currency, rates_info)

    return rates_info
  } catch ({ message}) {
    return create_api_message("danger", message)

And now am trying to call it both through Postman and the Function test calls in Moralis dashboard.

However I keep getting:

<!DOCTYPE html>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <base href="/"/>
            PARSE_DASHBOARD_PATH = "/";
    <title>Moralis Dashboard</title>
        <div id="login_mount"></div>
        <script id="csrf" type="application/json">"RWlPRCPU-7VloXr0iW-l25hVzCCE3ITKEdhQ"</script>
        <script src="/bundles/login.bundle.js"></script>

The function should reside here: https://myAccount.usemoralis.com:2083/server/functions/get_rates_for_currency?_ApplicationId=myAppID&currency=USD

Am I doing something wrong?

I don’t expect for axios to work in cloud code, but related to your error it looks like there was used the port number for the dashboard and not the port number for the server in that url. You should change that port number.

Axios works fine, at least it did so far on Firebase cloud functions.

I updated the port, so now its: https://myAccount.usemoralis.com:2053/server/functions/get_rates_for_currency?_ApplicationId=myAppID&currency=USD

However now the error is:

    "code": 141,
    "error": "Invalid function: \"get_rates_for_currency\""

When I look into my cloud function uploaded to the server, it seems to be uploaded correctly.

now you call the right function, but now it could be because that code doesn’t run, you can look in the dashboard for errors in logs. in Moralis cloud functions axios doesn’t work now from what I know

you could try with a simpler cloud function

Ok I have tested it with just returning the currency and that works, however my full code is throwing:

Error: Cloud Code tried to require '../functions/constans/other' but this is not a whitelisted module.

I couldnt find a way to whitelist a moule, is there some way to whitelist a complete folder, like: ../functions/**/*?

you can not whitelist a module now, you can use an alternative to axios with httpRequest: https://docs.moralis.io/moralis-server/cloud-code/httprequest

Well I have removed axios, the problem is with my local file import ('../functions/constans/other').

So is there currently no way to import local module/files into the cloud function file?

I think that you can do that, if you deploy the cloud code with moralis-admin-cli