Comments (1)
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)
- Export handler, hide FDK.handle HOT 1
- [object Object] returned by deployed function when invoked via curl HOT 6
- config values in YAML are not where expected in context
- override exit codes HOT 1
- Possible fdk-node on K8S issue? HOT 3
- stdin keep growing with input from all the POST HOT 3
- Support changes to Fn JSON format HOT 1
- [security] vulnerabilities being found in dependencies by npm
- ctx.headers returns values are array inside array
- FDK doesn't handle undefined response
- 405Method Not Allowed for all HTTP methods (GET/OPTIONS/PUT/DELETE) except POST HOT 1
- console.log pollutes stdout HOT 5
- Handler inconsistent parameters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fdk-node.