Coder Social home page Coder Social logo

Comments (1)

michael-w-williams avatar michael-w-williams commented on June 5, 2024

I have encountered the same problem while testing the new node tutorial. Here is the data I collected.

Currently using:

Client version:  0.4.66
Server version:  0.3.385

What works

The fn init --runtime node nodefn command generates the following function:

var fdk=require('@fnproject/fdk');

fdk.handle(function(input){
  var name = 'World';
  if (input.name) {
    name = input.name;
  }
  response = {'message': 'Hello ' + name}
  return response
})

This works fine with:

  • fn run
  • echo -n '{"name":"Bob"}' | fn run
  • fn call nodeapp /nodefn

The function returns:

{"message":"Hello World"}

or

{"message":"Hello Bob"}

Issue with Curl

However, when you call the function with curl you get a different result:

curl http://localhost:8080/r/nodeapp/nodefn

returns:

[object Object]

So to see the headers I tried again with --raw and I get:

curl -iv --raw http://localhost:8080/r/nodeapp/nodefn

returns

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /r/nodeapp/nodefn HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Length: 15
Content-Length: 15
< Content-Type: text/plain; charset=utf-8
Content-Type: text/plain; charset=utf-8
< Fn_call_id: 01C92WA4YH47WH200000000000
Fn_call_id: 01C92WA4YH47WH200000000000
< Xxx-Fxlb-Wait: 529.127504ms
Xxx-Fxlb-Wait: 529.127504ms
< Date: Tue, 20 Mar 2018 23:36:07 GMT
Date: Tue, 20 Mar 2018 23:36:07 GMT

<
* Connection #0 to host localhost left intact
[object Object]

An id is returned rather than JSON.

Different Return Statement

Looking at the docs in the FDK-Node repo I noticed a different return statement for the function was used in the docs.

var fdk=require('@fnproject/fdk');

fdk.handle(function(input){
  var name = 'World';
  if (input.name) {
    name = input.name;
  }
  response = {'message': 'Hello ' + name}
  return JSON.stringify(response)
})

Changing the return statement fixes the curl results. However, using fn run or fn call returns JSON in a sort of Java format:

"{\"message\":\"Hello World\"}"

Any assistance you can give is appreciated. Thanks.

from fdk-node.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.