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: dev server 504 with chunk loding #1611

Closed
wants to merge 2 commits into from
Closed

fix: dev server 504 with chunk loding #1611

wants to merge 2 commits into from

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Sep 25, 2024

problem

when ensure 5 or more chunks in browser, all the requests are proxied to mako dev server hyper; but hyper will reset connect at tcp level for some connection, at last results in some chunk's request gets 504 in browser.

wordaround

serve chunk files at node side

Summary by CodeRabbit

  • 新功能

    • 引入新的代理中间件,取代了之前的 express-http-proxy,增强了对响应处理的控制。
    • 现在应用可以根据配置异步提供静态文件。
  • 依赖更新

    • 移除了对 express-http-proxy 的依赖。

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

此次更改主要集中在 packages/bundler-mako/index.js 文件中,显著修改了 exports.dev 函数。移除了 express-http-proxy 依赖,新增了使用 createProxyMiddleware 的代理请求处理逻辑。应用程序现在根据 makoConfig 对象提供的路径异步服务静态文件。代理中间件的应用取决于 SSU 环境变量的设置,增强了对响应处理的控制。

Changes

文件路径 更改摘要
packages/bundler-mako/index.js 移除 express-http-proxy,引入 createProxyMiddleware,调整静态文件服务逻辑,makoConfig 变量声明移至函数开头。
packages/bundler-mako/package.json 移除依赖 "express-http-proxy": "^2.1.1"

Possibly related PRs

🐰 在草地上跳跃,代码如春风,
移除旧依赖,迎来新中间,
代理逻辑清晰,静态文件畅通,
兔子欢呼雀跃,代码更流畅!
🥕✨


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>, 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 resolve resolve all the CodeRabbit review comments.
  • @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
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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 68de8e2 and b22084f.

Files selected for processing (2)
  • packages/bundler-mako/index.js (2 hunks)
  • packages/bundler-mako/package.json (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • packages/bundler-mako/package.json

Comment on lines +131 to +144
let proxy = createProxyMiddleware({
target: `http://127.0.0.1:${hmrPort}`,
selfHandleResponse: true,
onProxyRes: (proxyRes, req, res) => {
if (proxyRes.statusCode !== 200) {
next();
} else {
proxyRes.pipe(res);
}
},
onError: (err, req, res) => {
next();
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议将 createProxyMiddleware 的实例移到中间件函数之外以提高性能

当前在每次请求时都会重新创建 proxy 实例,可能会影响性能。建议将 createProxyMiddleware 的实例化移到中间件函数外部,这样只需要创建一次代理,提高效率。

Comment on lines +141 to +143
onError: (err, req, res) => {
next();
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

错误处理时应传递错误对象给 next

onError 回调中,应该使用 next(err); 将错误对象传递给 Express 的错误处理中间件,而不是直接调用 next();。这有助于更好地捕获和处理错误信息。

Comment on lines +134 to +140
onProxyRes: (proxyRes, req, res) => {
if (proxyRes.statusCode !== 200) {
next();
} else {
proxyRes.pipe(res);
}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

需要在 onProxyRes 中设置响应的状态码和头信息

当使用 selfHandleResponse: true 时,需要手动将 proxyRes 的状态码和头信息复制到 res。当前只使用了 proxyRes.pipe(res);,但未设置状态码和头信息,可能导致客户端无法正确解析响应。建议在管道之前,添加以下代码:

+ res.writeHead(proxyRes.statusCode, proxyRes.headers);
  proxyRes.pipe(res);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onProxyRes: (proxyRes, req, res) => {
if (proxyRes.statusCode !== 200) {
next();
} else {
proxyRes.pipe(res);
}
},
onProxyRes: (proxyRes, req, res) => {
if (proxyRes.statusCode !== 200) {
next();
} else {
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res);
}
},

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.93%. Comparing base (68de8e2) to head (b22084f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1611   +/-   ##
=======================================
  Coverage   61.93%   61.93%           
=======================================
  Files         128      128           
  Lines       15405    15405           
=======================================
  Hits         9541     9541           
  Misses       5864     5864           

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

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.

1 participant