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

feat: allow set router host match #156

Merged
merged 1 commit into from
Jul 4, 2022
Merged

feat: allow set router host match #156

merged 1 commit into from
Jul 4, 2022

Conversation

yeliex
Copy link
Contributor

@yeliex yeliex commented Jul 4, 2022

If a server with many hosts and the same path in each host may different.

current version:

router.get('/', (ctx) => {
    if(ctx.host === 'a') // ...
    if(ctx.host === 'b') // ...
})

it is a good way to support host match in router definition:

// hosta.router.js
const routerA = new Router({
  host: 'hosta.com' // only match if request host exactly equal `hosta.com`
});
router.get('/', (ctx, next) => {
  // Response for hosta.com
});

// hostb.router.js
const routerB = new Router({
  host: /^(.*\.)?hostb\.com$/ // match all subdomains of hostb.com, including hostb.com, www.hostb.com, etc.
});
router.get('/', (ctx, next) => {
  // Response index for matched hosts
});

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.
  • [ x 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.

@yeliex
Copy link
Contributor Author

yeliex commented Jul 4, 2022

@titanism @etroynov pls

@titanism titanism merged commit d2ad849 into koajs:master Jul 4, 2022
@titanism
Copy link
Contributor

titanism commented Jul 4, 2022

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