serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

Doesn't work with netlify

Open richardanaya opened this issue 4 years ago • 5 comments

They use APIGatewayProxyEvent.

"errorMessage":"Unable to determine event source based on event."

Not sure why this isn't detected.

richardanaya avatar Jun 14 '21 06:06 richardanaya

Do you have an example app I can easily deploy?

brettstack avatar Jun 14 '21 06:06 brettstack

https://github.com/richardanaya/netlify

npm install netlify-cli -g
npm install
npm run build
netlify dev

checkout http://localhost:8888/.netlify/functions/hello

richardanaya avatar Jun 14 '21 06:06 richardanaya

It seems their event doesn't have a requestContext member.

If it helps I was able to get working with the alternate library serverless-http using these instructions: https://www.netlify.com/blog/2018/09/13/how-to-run-express.js-apps-with-netlify-functions/

spacem avatar Jul 22 '21 12:07 spacem

I'm running into this same exact issue, at least in development with netlify dev, which keeps me from using Apollo v3.

canac avatar Aug 17 '21 20:08 canac

Running locally with netlify dev seems to work if you monkey patch Netlify's event with the requestContext property:

import type { Handler } from "@netlify/functions";
import { ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";
import { ApolloServer } from "apollo-server-lambda";
import typeDefs from "../typeDefs";

const server = new ApolloServer({
  mocks: true,
  // @ts-ignore
  playground: true,
  plugins: [ApolloServerPluginLandingPageGraphQLPlayground()],
  typeDefs,
});

const apolloHandler = server.createHandler();

export const handler: Handler = (event: any, context: any, ...args) => {
  return apolloHandler(
    {
      ...event,
      requestContext: context,
    },
    context,
    ...args
  );
};

ryanvanoss avatar Sep 22 '21 04:09 ryanvanoss