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

getRouter is undefined #106

Open
tschaffter opened this issue Oct 17, 2022 · 1 comment
Open

getRouter is undefined #106

tschaffter opened this issue Oct 17, 2022 · 1 comment

Comments

@tschaffter
Copy link

tschaffter commented Oct 17, 2022

I'm trying to add HTTP routes to a Probot app deployed to AWS Lambda with your adapter. The HTTP route /api/hello-world added works when deploying the app locally with nodemon src/index.ts. However, the endpoint returns the error 500 when deployed to AWS Lambda with Serverless because getRouter is undefined.

2022-10-16T19:17:01.251Z	undefined	ERROR	Unhandled Promise Rejection 	
{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "Error: getRouter is undefined",
    "reason": {
        "errorType": "Error",
        "errorMessage": "getRouter is undefined",
        "stack": [
            "Error: getRouter is undefined",
            "    at /var/task/src/index.js:9:15",
            "    at Generator.next (<anonymous>)",
            "    at /var/task/node_modules/tslib/tslib.js:118:75",
            "    at new Promise (<anonymous>)",
            "    at Object.__awaiter (/var/task/node_modules/tslib/tslib.js:114:16)",
            "    at challengeBot (/var/task/src/index.js:7:54)",
            "    at Probot.load (/var/task/node_modules/probot/lib/probot.js:80:16)",
            "    at createLambdaFunction (/var/task/node_modules/@probot/adapter-aws-lambda-serverless/index.js:14:10)",
            "    at Object.<anonymous> (/var/task/src/lambda/handler.js:5:84)",
            "    at Module._compile (node:internal/modules/cjs/loader:1105:14)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: Error: getRouter is undefined",
        "    at process.<anonymous> (file:///var/runtime/index.mjs:1131:17)",
        "    at process.emit (node:events:527:28)",
        "    at process.emit (node:domain:475:12)",
        "    at emit (node:internal/process/promises:140:20)",
        "    at processPromiseRejections (node:internal/process/promises:274:27)",
        "    at processTicksAndRejections (node:internal/process/task_queues:97:32)"
    ]
}

Is this behavior to be expected when using this adatper and deploying on AWS lambda? Probot doc mentions that getRouter will be set only when running the app with probot run or using their Server.

src/index.ts:

import { ApplicationFunctionOptions, Probot, run } from 'probot';
import * as express from 'express';

export const challengeBot = async (
  app: Probot,
  { getRouter }: ApplicationFunctionOptions
): Promise<void> => {
  if (!getRouter) {
    throw new Error('getRouter is undefined');
  }

  const router = getRouter('/api');
  router.use(express.json());
  router.get('/hello-world', (req, res) => {
    res.json({ a: 1 });
  });

  app.on('issues.opened', async (context) => {
    const issueComment = context.issue({
      body: 'Thanks for opening this issue!',
    });
    await context.octokit.issues.createComment(issueComment);
  });
};

run(challengeBot);
@tschaffter tschaffter changed the title getRouter is undefined getRouter is undefined Oct 17, 2022
@tschaffter
Copy link
Author

This statement is shedding some light on the issue reported:

We will likely remove the getRouter function in a future Probot version altogether as it cannot be supported in serverless environments. We will instead ask people to use the Server export instead and define their custom routes that way.

Source

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

1 participant