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

fix: undefined property in unmatched host #178

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

laverdet
Copy link
Contributor

allowedMethods() throws a runtime error when the host of its router fails to match. Additionally it would throw if you never added routes() to your koa middleware chain.

Example:

import Router from "@koa/router";
import Koa from "koa";

const app = new Koa();
const router = new Router({ host: "aaaa" });
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(8888);
$ curl localhost:8888/                   
Internal Server Error

Error:

  TypeError: Cannot read properties of undefined (reading 'length')
      at /Users/marcel/braid/web/.pnpm/@koa+router@12.0.1/node_modules/@koa/router/lib/router.js:487:41
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

Copy link
Member

@3imed-jaberi 3imed-jaberi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laverdet, thanks a great catch 🚀 !

@3imed-jaberi 3imed-jaberi merged commit 31deae8 into koajs:master Aug 15, 2024
2 of 5 checks passed
@3imed-jaberi 3imed-jaberi self-assigned this Aug 15, 2024
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

Successfully merging this pull request may close these issues.

2 participants