fnproject / fdk-node Goto Github PK
View Code? Open in Web Editor NEWExperimental FDK for Node.js
License: Apache License 2.0
Experimental FDK for Node.js
License: Apache License 2.0
In the node.js fn handler, the ctx parameter headers property returns:
get headers () {
let headers = {}
for (let k in this._headers) {
if (this._headers.hasOwnProperty(k)) {
headers[k] = new Array(this._headers[k])
}
}
return headers
}
However _headers[k] is already an array, so to get the value for a header you need:
ctx.headers["Content-type"][0]0] which does not seem right.
from recent fdk builds:
added 241 packages from 175 contributors and audited 657 packages in 2.746s
found 4 vulnerabilities (2 moderate, 2 high)
run `npm audit fix` to fix them, or `npm audit` for details
not a nodejs expert, but i guess this should be fixed.
Docker uses: http://tldp.org/LDP/abs/html/exitcodes.html
Make sure FDK does not allow functions to exit with these codes.
For example, 137 exit code is currently flagged as OOM in fn-agent, therefore functions should not be allowed to exit with 137 themselves.
console.log seems to be directed to stdout by default:
in a JSON function :
const fdk = require('@fnproject/fdk')
fdk.handle(function (input, ctx) {
console.log("Running function")
return "OK"
})
causes a JSON parse error in fn:
{"error":{"message":"invalid json response from function err: invalid character 'R' looking for beginning of value"}}
console
is assignable so fix is to replace it with a monkey-patched version that sends logs to stderr only .
Deployed it to local server and the response body is [object Object].
Similar to what most of the serverless do for node.js - make handler call implicit by making that exportable.
The current boilerplate generated Node.js example returns [object Object]
instead of the expected JSON response when called via curl/direct http. Console output:
$ curl http://localhost:8080/r/demo/hello
[object Object]
I tried explicitly specifying Content-Type: application/json
but there was no change. However when I called the function with fn call
the function returns the expected JSON:
$ fn call demo hello
{"message":"Hello World"}
The output is essentially the same whether input is provided or not.
Client version: 0.4.66
Server version: 0.3.410
FDK version (in boilerplate package.json): 0.x
See fnproject/fn#662 (issue) and fnproject/fn#724 (implementation).
Information that was previously stored in FN-prefixed headers has been promoted to first-class JSON fields. Details in the references above.
Hi there,
I'm running fn on a K8S cluster and can run through the Go instructions just fine:
https://fnproject.io/tutorials/Introduction/
But when following their Node equivalent:
https://fnproject.io/tutorials/node/intro/
The fn invoke nodeapp nodefn
sends back a 500 error and the fn list calls
comes back empty. Here's a full set of commands I'm running with results:
PETERCJO-M-63N9:fn petercjo$ fn init --runtime node --trigger http nodefn
Creating function at: /nodefn
Function boilerplate generated.
func.yaml created.
PETERCJO-M-63N9:fn petercjo$ cd nodefn
PETERCJO-M-63N9:nodefn petercjo$ ll
total 24
-rw-r--r-- 1 petercjo staff 176 Oct 2 17:24 func.js
-rw-r--r-- 1 petercjo staff 184 Oct 2 17:24 func.yaml
-rw-r--r-- 1 petercjo staff 193 Oct 2 17:24 package.json
PETERCJO-M-63N9:nodefn petercjo$ fn --verbose deploy --app nodeapp
Deploying nodefn to app: nodeapp
Bumped to version 0.0.2
Building image petecj2/nodefn:0.0.2
FN_REGISTRY: petecj2
Current Context: No context currently in use.
Sending build context to Docker daemon 5.12kB
Step 1/9 : FROM fnproject/node:dev as build-stage
---> 016382f39a51
Step 2/9 : WORKDIR /function
---> Using cache
---> 8c66c3b8b760
Step 3/9 : ADD package.json /function/
---> Using cache
---> a8e6bba754a8
Step 4/9 : RUN npm install
---> Using cache
---> 366077317d69
Step 5/9 : FROM fnproject/node
---> 016382f39a51
Step 6/9 : WORKDIR /function
---> Using cache
---> 8c66c3b8b760
Step 7/9 : ADD . /function/
---> df3bd424e08c
Step 8/9 : COPY --from=build-stage /function/node_modules/ /function/node_modules/
---> 0970aa10bd82
Step 9/9 : ENTRYPOINT ["node", "func.js"]
---> Running in 784bb14078af
Removing intermediate container 784bb14078af
---> 2b1157cd2228
Successfully built 2b1157cd2228
Successfully tagged petecj2/nodefn:0.0.2
Parts: [petecj2 nodefn:0.0.2]
Pushing petecj2/nodefn:0.0.2 to docker registry...The push refers to repository [docker.io/petecj2/nodefn]
4c4d0bf877e9: Pushed
0b2623d672cd: Pushed
4541c185b2ea: Pushed
0b3e54ee2e85: Mounted from fnproject/node
ad77849d4540: Mounted from fnproject/node
5bef08742407: Mounted from fnproject/node
0.0.2: digest: sha256:c75c2ffb8806778d3f89983b1185ea4261d0615912a1fe70a17a083059f6cda8 size: 1572
Updating function nodefn using image petecj2/nodefn:0.0.2...
Successfully created app: nodeapp
Successfully created function: nodefn with petecj2/nodefn:0.0.2
Successfully created trigger: nodefn-trigger
PETERCJO-M-63N9:nodefn petercjo$ fn invoke nodeapp nodefn
{"message":"internal server error"}
Fn: Error calling function: status 500
See 'fn <command> --help' for more information. Client version: 0.5.13
PETERCJO-M-63N9:nodefn petercjo$ fn list calls nodeapp nodefn
PETERCJO-M-63N9:nodefn petercjo$
The only thing I did differently, and had to do the same on the Go example, was I didn't use the --local
flag on the deploy command since I'm running on a remote K8S cluster instead of my local Docker.
Thoughts? Other logs I should be looking at?
I'd be happy to post a similar output for the successful set of Go commands if that'll help.
Does fn support only HTTP POST Method. i am trying to build a function and call it from a SPA which needs CORS Support and essentially OPTIONS Call . from Post man i keep getting 405Method Not Allowed .
So, all other FDKs place the context as a 1st parameter and the data as the 2nd one. Here we should do the same.
Hi,
I have a simple func.js
var fdk=require('@fnproject/fdk');
fdk.handle( function(input) {
return input
})
the function continue to append the input data from previous call until the docker is running (I use http-stream )
postak@mbp13 curl -X POST -d @payload.json 'http://127.0.0.1:8080/t/myapp/myfunc
"ciao"postak@mbp13 curl -X POST -d @payload.json 'http://127.0.0.1:8080/t/myapp/myfunc
"ciaociao"postak@mbp13 curl -X POST -d @payload.json 'http://127.0.0.1:8080/t/myapp/myfunc
"ciaociaociao"postak@mbp13 curl -X POST -d @payload.json 'http://127.0.0.1:8080/t/myapp/myfunc
"ciaociaociaociao"postak@mbp13 curl -X POST -d @payload.json 'http://127.0.0.1:8080/t/myapp/myfunc
this is my func.yaml
schema_version: 20180708
name: myfunc
version: 0.0.66
runtime: node
entrypoint: node func.js
format: http-stream
triggers:
- name: myfunc
type: http
source: /myfunc
If I return undefined on the fdk it hangs until the function timeout.
I have a function that if there's an error, it just console.error('error message') and then return. When I try to invoke fn function it hangs until it timeout.
fdk.handle(async event => {
const result = await someAwaitFunction()
if(result.error) {
console.error(result.error)
return
}
....
})
fdk: 0.0.15
fn: 0.5.96
In my func.yaml file I have this
name: crawl
version: 0.0.4
runtime: node
entrypoint: node func.js
type: async
format: json
timeout: 1800
config:
ALLOWED_HTTP_METHOD: POST
FN_SERVER_HOST: http://someurl.com
FN_TEST: test value
idle_timeout: 3600
In the context I receive when running
ALLOWED_HTTP_METHOD is under ctx.config.properties.ALLOWED_HTTP_METHOD
which is reasonable.
but the other two config values I added show up under
ctx.payload.server_host
ctx.payload.test
different path, lower case and removal of FN_
is there a reason this is so obfuscated?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.