Invoke the express function on the client using the callable method

When I'm listening on a local port with my browser, the following method will return Hello world.

//Node

app.get('/', (req,res)=>{
        res.send('Hello world')
        });

I've successfully exported the app as a callable cloud function named: getConstits.

//Node

exports.getConstits = functions.https.onCall(app);

Next, I call the function in my client.

//Client

final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
    functionName: 'getConstits',
);


getElec()async {
    dynamic resp = await callable.call();
    print(resp);
}

However, upon calling the function, an unhandled exception is thrown. The URL generated by the cloud function responds with

{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
. How can I ensure that "Hello World" is returned to the client?

Answer №1

Express apps do not support callable functions like regular HTTP functions do.

If you wish to create an express app and deploy it to Cloud Functions, you must follow the guidelines for integrating express apps with HTTP functions. By doing so, you will not be able to utilize the callable function SDK on the client side - a standard HTTP library will have to be used instead.

To create a callable function that can be accessed with the provided client SDK, you only need to write the function's logic without relying on express. The callable SDK manages all the HTTP implementation details automatically.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the proper way to define an array of objects in TypeScript?

In search of a way to define a function that accepts an array of unspecified object types, known as "anonymous types." I want to enforce strict typing with TypeScript. The objects in the array all have properties like name, price, and description. bagTotal ...

How can I troubleshoot jQuery not functioning in iOS even though it works on Safari?

Trying to implement jQuery on a website using xCode simulator for testing, but experiencing issues. Works fine on Safari webkit though. Click here to view the site. I would appreciate finding out what's causing the problem, as well as advice on how t ...

When embedding HTML inside an Angular 2 component, it does not render properly

Currently, I am utilizing a service to dynamically alter the content within my header based on the specific page being visited. However, I have encountered an issue where any HTML code placed within my component does not render in the browser as expected ( ...

The processing indicator fails to function properly when trying to refresh a jQuery datatable

I am currently customizing the loading indicator for the datatable using a spinner called startLoadGlobal(SPINNER_DATA_TABLE_FINANCEIRO_CARREGAR_REGISTROS) in jQuery. It works correctly when I initially load the datatable, however, when I reload it, the sp ...

arranging <li> elements in alphabetical order

I'm looking for a way to alphabetically sort an unordered list while still keeping the outer html intact. My current method sorts the list alphabetically, but it only reorganizes the inner html of the list elements and not the entire element itself. T ...

Is it possible to perform a PHP redirect after the headers have been

I am encountering an issue with a function that needs to redirect the page once a variable is set. The challenge arises from the fact that this function is located at the bottom of the PHP page. As a result, I have already displayed a significant amount ...

Is there a way to dynamically update the TargetControlID of an AutoCompleteExtender using client-side JavaScript?

Typically, I am able to set the TargetControlID on the server side using code similar to this: AutoCompleteExtender ace = new AutoCompleteExtender(); ace.ID = "AutoCompleteExtender1"; ace.TargetControlID = "whatever"; While I understand how t ...

How do you properly bind multiple events in jQuery and then unbind just a few of them?

Is it possible to bind multiple events, then unbind a couple of them? This is what I'm trying to achieve: When hovering over the element, the background color changes and changes back when hovering out. But when clicking the element, I want to disabl ...

When attempting to transfer data from a client to a server, a "Bad Request" error is encountered with the message: `POST http://localhost:5000/api

Hey everyone, I'm facing an issue with sending user data from the client-side to the server-side. Whenever I try to send new user details to the server, I encounter the following error: An alert pops up with the message "Enter valid credentials" and ...

Exploring the dynamic duo of MongoDB and GridFS

We currently manage a large-scale project that accommodates thousands of users daily. Our database system is MySQL, but we are considering transitioning to MongoDB along with GridFS. Is it feasible to utilize MongoDB and GridFS for projects on this scale? ...

Dealing with Unexpected Timeout Errors and Memory Leaks in Express/Typescript Using Jest, Supertest, and TypeORM

Currently, I am in the process of writing unit tests for an express API. Each test suite initiates a fresh instance of an express server before running the tests. Individually, each test suite runs smoothly without any problems. However, when executed tog ...

Transform any falsy values within a JavaScript object into an empty string

Looking for a solution to transform all undefined, NaN, etc. values in a Javascript object into an empty string for better definition. For example: javascriptObject = convertUndefined(javascriptObject) Seeking something that can achieve this functionalit ...

Tips for transferring information from controller JavaScript to view JavaScript within AngularJS

Currently, I am working on an angularJS application where I retrieve data from a REST service within the controller. The retrieved data is then passed to the view using $scope. However, I encountered an issue when trying to use this data in my in-page Java ...

Sorting through an array of dates in milliseconds, extracting objects with subcategories, and dynamically displaying them on the calendar based on the specific date

So I am currently working with a JSON object containing an array of objects structured like this: [ { "id": 0, "name": "Sophia Mason", "availability": [ { "date": 1522216800000, "times": ["9:00 am", "2:3 ...

Create a function that binds a select dropdown to each table column header using JavaScript Object Notation (JSON), and then populate an HTML table with the

I have a dynamic table populated with JSON data, and I would like to add a select dropdown for each column. The challenge is that the number of columns is not fixed and they are also populated by JSON. Therefore, I want the select dropdown at the top of ea ...

VueJS can manipulate an inline template by dynamically changing its content and reinitializing

this particular query shares similarities with the discussions on VueJS re-compiling HTML in an inline-template component as well as How to implement Vue js directive in an appended html element Regrettably, the approach suggested in those threads is no l ...

Submit form data asynchronously using Ajax and serialize the form data before posting

I'm currently facing an issue with posting HTML form values in my code. Everything works fine except for the fact that I can't get it to post single quotes ' . I believe this problem is caused by the usage of serialize. I've attempted c ...

Guide to removing a Firebase collection within a Vue.js component

I'm working on a Vue.js component that retrieves data dynamically from Firebase, and I want to make sure I unsubscribe when exiting the component. The Firebase documentation specifies using the unsubscribe() function to stop listening to the collecti ...

Stop the click event using a confirmation dialog before proceeding with the operation

I'm trying to implement a confirmation dialog before deletion by using e.preventDefault() to prevent immediate deletion. However, I am facing an issue in the YES function where I would like to resume the click event's operation with return true w ...

Error in Node.js when connecting to PostgreSQL: host is not listed in pg_hba.conf

I came across an interesting article on connecting to a PostgreSQL database from Node.js using the PG module at (). After deploying my app to Heroku and incorporating Express, Node.js, I attempted to connect to a PostgresSQL database in Heroku. However, wh ...