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: resources should support multiple middlewares #21

Merged
merged 2 commits into from
Mar 27, 2025
Merged

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 27, 2025

closes eggjs/egg#5410

Summary by CodeRabbit

  • New Features
    • Enhanced route configuration to support defining resources with multiple middleware functions, offering more modular and flexible handling.
  • Tests
    • Added new tests to verify that resource registration correctly integrates multiple middleware functions.

@fengmk2 fengmk2 requested a review from Copilot March 27, 2025 12:03
Copy link

coderabbitai bot commented Mar 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request updates the EggRouter class by enhancing the resources method. Specifically, the method signatures are modified to accept a variable number of middleware functions via a rest parameter. This change allows for more flexible and modular route handling. Additionally, a new test case is added to verify the functionality of registering multiple middleware functions with a resource route.

Changes

File(s) Change Summary
src/EggRouter.ts Updated resources method signatures to accept a rest parameter for multiple middleware functions and adjusted parameter order accordingly.
test/EggRouter.test.ts Added a new test case to validate that registering multiple middleware functions with a resource route correctly updates the router and middleware stack.

Assessment against linked issues

Objective Addressed Explanation
Support multiple middleware functions in route registration (#5410)

Possibly related PRs

Poem

I'm a rabbit with a joyful beat,
Hopping through routes both nimble and neat.
Multiple middlewares make my heart skip a pace,
Carrot-code and routes in a lively embrace! 🥕🐇
Cheers to clean paths and code full of grace!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/EggRouter.test.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7d54e9 and 89a3c73.

📒 Files selected for processing (1)
  • test/EggRouter.test.ts (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the issue where resources need to support multiple middlewares. It adds tests to verify that multiple middlewares work correctly with the resources method and updates the EggRouter API overloads and documentation to support this functionality.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/EggRouter.test.ts Added tests to verify that calling router.resources() with multiple middlewares works.
src/EggRouter.ts Updated the method overloads and documentation to support multiple middlewares.
Comments suppressed due to low confidence (1)

test/EggRouter.test.ts:334

  • [nitpick] The test description references 'app.resource()' instead of 'app.resources()'. Consider renaming it for consistency with the actual method name.
it('should app.resource() with multiple middlewares work', () => {

Copy link

codecov bot commented Mar 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.18%. Comparing base (a1a3b68) to head (89a3c73).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #21   +/-   ##
=======================================
  Coverage   99.18%   99.18%           
=======================================
  Files           4        4           
  Lines        1719     1721    +2     
  Branches      227      227           
=======================================
+ Hits         1705     1707    +2     
  Misses         14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 merged commit acb9c4b into master Mar 27, 2025
9 of 10 checks passed
@fengmk2 fengmk2 deleted the fix-types-2 branch March 27, 2025 12:07
fengmk2 pushed a commit that referenced this pull request Mar 27, 2025
[skip ci]

## [3.0.6](v3.0.5...v3.0.6) (2025-03-27)

### Bug Fixes

* resources should support multiple middlewares ([#21](#21)) ([acb9c4b](acb9c4b))
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.

如何在4.0+的版本中,在路由设置中,使用多个中间件?
1 participant