Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

fix: fn is not a function #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix: fn is not a function #1

wants to merge 1 commit into from

Conversation

helio-frota
Copy link

This commit fix the previous error:

server listening on 8080
/usr/libexec/s2i/ocf-nodejs-adapter/handler.js:6
    fn(ctx);
    ^

TypeError: fn is not a function
    at Server.<anonymous> (/usr/libexec/s2i/ocf-nodejs-adapter/handler.js:6:5)
    at Server.emit (events.js:182:13)
    at parserOnIncoming (_http_server.js:652:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)

And now we able to see the future/next error:

server listening on 8080
loading: [object Object]
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module '/opt/app-root/src/[object Object]'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at module.exports (/opt/app-root/src/load.js:3:10)
    at adapt (/opt/app-root/src/index.js:5:14)
    at Server.<anonymous> (/usr/libexec/s2i/ocf-nodejs-adapter/handler.js:6:5)
    at Server.emit (events.js:182:13)
    at parserOnIncoming (_http_server.js:652:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)

This commit fix the previous error:

```
server listening on 8080
/usr/libexec/s2i/ocf-nodejs-adapter/handler.js:6
    fn(ctx);
    ^

TypeError: fn is not a function
    at Server.<anonymous> (/usr/libexec/s2i/ocf-nodejs-adapter/handler.js:6:5)
    at Server.emit (events.js:182:13)
    at parserOnIncoming (_http_server.js:652:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
```

And now we able to see the future/next error:

```
server listening on 8080
loading: [object Object]
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module '/opt/app-root/src/[object Object]'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at module.exports (/opt/app-root/src/load.js:3:10)
    at adapt (/opt/app-root/src/index.js:5:14)
    at Server.<anonymous> (/usr/libexec/s2i/ocf-nodejs-adapter/handler.js:6:5)
    at Server.emit (events.js:182:13)
    at parserOnIncoming (_http_server.js:652:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
```
@bobmcwhirter
Copy link
Contributor

bobmcwhirter commented Oct 11, 2018

where does this adapt come from?

My original code is pretty crap-tastic, I do realize. :)

The idea was to wrap the raw function with another function that handles the httpHandler bits, and then wrap that all entirely with the httpServer.

So would prefer being able to wrap any random function, instead of requiring anyone to write an adapt specifically.

@helio-frota
Copy link
Author

where does this adapt come from?

I just added console.log('fn', fn); to see what is happening, and it shows an object instead a function
{adapt: [function] adapt}

My original code is pretty crap-tastic, I do realize. :)

Nah, basically linting issues other than that is good 👍

The idea was to wrap the raw function with another function that handles the httpHandler bits, and then wrap that all entirely with the httpServer.

I think I got your idea.

So would prefer being able to wrap any random function, instead of requiring anyone to write an adapt specifically.

Makes sense, It was a quick shot , I was curious to see it working. : ]

@bobmcwhirter
Copy link
Contributor

So ultimately this needs to be run from within a different project

The entry-point is

https://github.com/openshift-cloud-functions/ocf-nodejs-adapter/blob/master/bin/run.js

but then it takes the path to your function (in a different project which should be your $PWD) or figures it out from the main of your package.json to use as the function.

Then Adapter.adapt( yourFunction ) . which should wrap the fn and plonk it into the httpServer.

In theory.

The s2i works by changing into the $PWD of the fn project (such as https://github.com/openshift-cloud-functions/ocf-nodejs-example), then running the above run.js using a fully-qualified path.

(see the README in the example project: https://github.com/openshift-cloud-functions/ocf-nodejs-example/blob/master/README)

@helio-frota
Copy link
Author

helio-frota commented Oct 11, 2018

Thanks for the extra clarification.

yah this is the full path '/opt/app-root/src/[object Object]' from the error message on the commit comment.

I think this needs JSON.stringify to be -> /opt/app-root/src/index.js

@bobmcwhirter
Copy link
Contributor

bobmcwhirter commented Oct 11, 2018 via email

@helio-frota
Copy link
Author

Yup me too

hf@hf-ThinkPad-T440:~$ node --version
v10.11.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants