Skip to content

getRouter is undefined #106

Open
Open
@tschaffter

Description

@tschaffter

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions