Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

claudia update fails with latest fastify version #28

Open
veedeo opened this issue May 29, 2018 · 8 comments
Open

claudia update fails with latest fastify version #28

veedeo opened this issue May 29, 2018 · 8 comments

Comments

@veedeo
Copy link

veedeo commented May 29, 2018

TypeError: "listener" argument must be a function
    at _addListener (events.js:239:11)
    at Server.addListener (events.js:297:10)
    at new Server (_http_server.js:269:10)
    at Object.createServer (http.js:34:10)
@kwalski
Copy link

kwalski commented Oct 16, 2018

any fix for this?

@veedeo
Copy link
Author

veedeo commented Oct 16, 2018

I don't remember what was the problem exactly. but this is correct entry point for latest version:

import Fastify from 'fastify';
import awsServerlessExpress from 'aws-serverless-express';
import api from './api';

const app = Fastify({
  serverFactory(handlerMethod) {
    return awsServerlessExpress.createServer(handlerMethod);
  },
});
api(app);
app.ready(() => console.log('Ready'));

export function handler(event, context) {
	return awsServerlessExpress.proxy(app.server, event, context);
}

@kwalski
Copy link

kwalski commented Oct 16, 2018

@veedeo your guidance has been mighty helpful! Thank you 👍

@kwalski
Copy link

kwalski commented Oct 16, 2018

I recommend calling awsServerlessExpress.proxy inside app.ready callback, as in my case, proxy was calling fastify routes prematurely

@veedeo
Copy link
Author

veedeo commented Oct 17, 2018

Can you share the code?

@kwalski
Copy link

kwalski commented Oct 17, 2018

in my api, I was creating a database connection during fastify initialization which was delaying fastify readiness before awsServerlessExpress.proxy call and fastify's route hanler was not being called. The following change will ensure fastify is ready

import Fastify from 'fastify';
import awsServerlessExpress from 'aws-serverless-express';
import api from './api';

const app = Fastify({
  serverFactory(handlerMethod) {
    return awsServerlessExpress.createServer(handlerMethod);
  },
});
api(app);

export function handler(event, context) {
  app.ready((err) => { 
       console.log(err?err:'Ready');
       return awsServerlessExpress.proxy(app.server, event, context);
  });
}

@adrai
Copy link
Contributor

adrai commented Apr 2, 2019

@adrai
Copy link
Contributor

adrai commented Apr 15, 2019

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

No branches or pull requests

3 participants