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

refactor: Unify the static server in bundler-mako and devServer #1468

Merged
merged 8 commits into from
Aug 29, 2024

Conversation

whyer11
Copy link
Contributor

@whyer11 whyer11 commented Aug 4, 2024

Unify the static server in bundler-mako and devServer, and fix the bug where devServer cannot correctly match static resources.

Summary by CodeRabbit

  • 新功能

    • 改进了 DevServer 处理静态文件的方式,增强了 HTTP 请求处理机制。
    • 新增调试日志,记录请求方法和 URI 路径。
  • 性能改进

    • 精简了请求处理逻辑,提高了性能和代码可读性。

Copy link
Contributor

coderabbitai bot commented Aug 4, 2024

Walkthrough

此次更改在DevServer和请求处理逻辑中进行了重要调整,提升了静态文件处理的能力。通过使用hyper库构建HTTP请求,改进了请求逻辑,添加了调试日志,简化了处理流程,使其直接根据请求方法和内容类型进行判断。这种改进减少了复杂性,提高了性能,使得开发服务器的功能更加强大。

Changes

文件 更改摘要
crates/mako/src/dev/mod.rs DevServer中添加了使用hyper构建HTTP请求的代码,并更新了静态内容服务的条件。
crates/mako/src/dev.rs 修改了静态内容服务的逻辑,添加了对write_to_disk配置的检查,增加了调试日志,并构建HTTP响应。
packages/bundler-mako/index.js 移除了processReqURL函数,简化了HTTP请求处理逻辑,直接根据请求方法和内容类型进行判断。

Poem

🐰 在草地上跳跃,代码更美妙,
静态文件处理,像花儿一样娇。
HTTP请求,轻松又简单,
开发者欢笑,兔子跟着跳!
新逻辑如春风,伴随每个调用。 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@whyer11 whyer11 changed the title refactor: Unify the static server in bundler-mako and devServer [WIP] refactor: Unify the static server in bundler-mako and devServer Aug 4, 2024
@whyer11 whyer11 changed the title [WIP] refactor: Unify the static server in bundler-mako and devServer wip: refactor: Unify the static server in bundler-mako and devServer Aug 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47aaf56 and fe746e4.

Files selected for processing (2)
  • crates/mako/src/dev/mod.rs (1 hunks)
  • packages/bundler-mako/index.js (1 hunks)
Additional comments not posted (2)
crates/mako/src/dev/mod.rs (1)

200-203: 改进了静态文件的处理方式

新的代码段使用 hyper 库构建 HTTP 请求,并通过 staticfile.serve 进行处理。这种改进可能提高了静态文件处理的性能和一致性。

请确保在其他地方调用该函数时没有问题。

Verification successful

改进了静态文件的处理方式

新的代码段使用 hyper 库构建 HTTP 请求,并通过 staticfile.serve 进行处理。这种改进可能提高了静态文件处理的性能和一致性。

  • crates/mako/src/dev/mod.rs:200-203
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `staticfile.serve` to ensure it aligns with the new request construction.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'staticfile.serve'

Length of output: 698

packages/bundler-mako/index.js (1)

111-121: 简化了请求处理逻辑

新的代码段通过直接检查请求方法和内容类型简化了请求处理逻辑。这种改进可能提高了性能和可维护性。

请确保在其他地方调用该函数时没有问题。

Verification successful

简化了请求处理逻辑

新的代码段通过直接检查请求方法和内容类型简化了请求处理逻辑。这种改进可能提高了性能和可维护性。

  • packages/bundler-mako/index.js 中的逻辑一致,且没有发现其他不一致的调用。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the modified request handling logic to ensure it aligns with the new implementation.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type js -A 5 $'req.method !== \'GET\' && req.method !== \'HEAD\''

Length of output: 796

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe746e4 and fc666d2.

Files selected for processing (1)
  • packages/bundler-mako/index.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/bundler-mako/index.js

@whyer11 whyer11 changed the title wip: refactor: Unify the static server in bundler-mako and devServer refactor: Unify the static server in bundler-mako and devServer Aug 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc666d2 and 8a7ed02.

Files selected for processing (1)
  • crates/mako/src/dev/mod.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/mako/src/dev/mod.rs

@whyer11 whyer11 requested review from sorrycc and stormslowly August 15, 2024 09:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a7ed02 and 35b8b1f.

Files selected for processing (2)
  • crates/mako/src/dev.rs (2 hunks)
  • packages/bundler-mako/index.js (1 hunks)
Additional comments not posted (4)
crates/mako/src/dev.rs (2)

174-183: 确保静态内容的正确处理

在处理静态内容时,增加了对 context.config.write_to_disk 的检查。这段代码逻辑合理,但需要确保 context.get_static_content 方法在所有可能的路径都能正确返回内容。

请确保 context.get_static_content 方法在所有可能的路径都能正确返回内容。


202-205: 改进请求构建

使用 hyper::Request::builder() 构建请求对象是一个不错的选择,但需要确保 path 变量的值始终是一个有效的 URI。

请确保 path 变量的值始终是一个有效的 URI。

packages/bundler-mako/index.js (2)

114-116: 改进请求方法检查

在检查请求方法时,确保只处理 GETHEAD 请求是一个好主意。这可以防止不必要的请求被处理。

这段代码更改是合理的。


118-124: 改进内容类型检查

检查请求是否接受 HTML 内容是一个好主意,但需要确保 req.accepts() 方法始终返回一个有效的数组。

请确保 req.accepts() 方法始终返回一个有效的数组。

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.91%. Comparing base (95a1a21) to head (10e8f08).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1468      +/-   ##
==========================================
- Coverage   60.94%   60.91%   -0.03%     
==========================================
  Files         126      126              
  Lines       15121    15135      +14     
==========================================
+ Hits         9215     9219       +4     
- Misses       5906     5916      +10     

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35b8b1f and b69f33a.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (1)
  • crates/mako/src/dev.rs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/mako/src/dev.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b69f33a and 10e8f08.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (1)
  • packages/bundler-mako/index.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/bundler-mako/index.js

@whyer11 whyer11 self-assigned this Aug 29, 2024
@stormslowly stormslowly merged commit 895d294 into master Aug 29, 2024
17 of 18 checks passed
@stormslowly stormslowly deleted the refact/universe_devserver branch August 29, 2024 06:19
stormslowly added a commit that referenced this pull request Sep 3, 2024
stormslowly added a commit that referenced this pull request Sep 3, 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
2 participants