Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript function making an api call to http://localhost:8080 vs https://app.mydomain.com #400

Open
jankrynauw opened this issue Feb 28, 2024 · 0 comments
Assignees
Labels
Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP

Comments

@jankrynauw
Copy link

jankrynauw commented Feb 28, 2024

Expected behavior

I have defined the following javascript function within my functsion.ts file:

/* global clearInterval, console, CustomFunctions, setInterval */
/**
 * Calculate the Present Value of a Policy
 * @customfunction
 * @param deathBenefit Death Benefit
 * @param discountRate Discount Rate
 * @param policyTerm Policy Term
 * @returns The Present Value
 */
export async function calculate(deathBenefit: number, discountRate: number, policyTerm: number): Promise<string> {
  // let host = "https://app.mydomain.com"; // does work.
  let host = "http://localhost:8080"; // does not work
  // let host = "http://ngrok...url"; // an Ngrok url pointing to my localhost:8080 does work
  // let host = "https://...-8080.inc1.devtunnels.ms"; // microsoft dev tunnels does not work.

  try {
    let request = new CalculateTermLifePresentValueRequest();
    request.setDeathBenefit(deathBenefit);
    request.setDiscountRate(discountRate);
    request.setPolicyTerm(policyTerm);

    let api = new ExcelServicePromiseClient(host);
    let response = await api.calculateTermLifePresentValue(request);
    return JSON.stringify(response.getResults().getBasicValue());

  } catch (e) {
    console.error("Error:", e.code, e.message); // Detailed output
    return `host: ${host}, ${JSON.stringify(e)}`;
  }
}

Current behavior

When I spin up a local server at http://localhost:8080, and update the host to this local endpoint, the method fails with the following error:

host: http://localhost:8080, {"message":"Http response at 400 or 500 level, http status code: 0","stack":"E@https://localhost:3000/functions.js:2389:68\nY@https://localhost:3000/functions.js:2425:45\n@https://localhost:3000/functions.js:2423:197\nKb@https://localhost:3000/functions.js:2401:186\nO@https://localhost:3000/functions.js:2400:616\nzc@https://localhost:3000/functions.js:2411:412\nBc@https://localhost:3000/functions.js:2414:230\n@https://localhost:3000/functions.js:2412:254\n@https://localhost:3000/functions.js:2412:232","code":2,"metadata":{}}

Steps to Reproduce

To confirm that my server at http://localhost:8080 works, I created an Ngrok endpoint, to my host. And when using the public Ngrok as the host, the api call is made successfully.

Also deploying this api server to a custom domain say http://api.mydomain.com also works.

Any idea why the local host would not work?

The order of events:

  1. Spin up an api server at http://localhost:8080 to serve the api call made within the functions.ts file.
  2. webpack serve --mode development
  3. office-addin-debugging start manifest.xml
  4. Navigate to the opened MS Excel and test the method: CONTOSO.CALCULATE
@millerds millerds transferred this issue from OfficeDev/Office-Addin-Scripts Feb 29, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP
Projects
None yet
Development

No branches or pull requests

4 participants