-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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: socket-server 根据 env.HOST 生成 #12281
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
WalkthroughThe update enhances the Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
Size Change: +237 B (0%) Total Size: 9.9 MB
ℹ️ View Unchanged
|
export function resolveDefine(opts: IResolveDefineOpts) { | ||
const env: Record<string, any> = {}; | ||
Object.keys(process.env).forEach((key) => { | ||
if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) { | ||
env[key] = process.env[key]; | ||
// 带 UMI_APP_ 前缀的和 ENV_SHOULD_PASS 定义的环境变量需要透传 | ||
ENV_SHOULD_PASS.concat( | ||
Object.keys(process.env).filter((k) => prefixRE.test(k)), | ||
).forEach((key: string) => { | ||
const envValue = EnvGetter[key] ? EnvGetter[key](opts) : process.env[key]; | ||
if (typeof envValue === 'undefined') { | ||
return; | ||
} | ||
env[key] = envValue; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段恢复成之前的逻辑吧,在之前的逻辑基础上加下面这行就好。因为这样改完之后并没有更好懂。
env[key] = EnvGetter[key] ? EnvGetter[key](opts) : process.env[key];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最开始就是这么写的,但是存在两个问题:
- SOCKET_SERVER 不存在时,在 process.env 的 keys 遍历就不会走到它了
- env[key] = undefined 和 env[key] 不存在是有区别的,担心会影响后续逻辑
!['0.0.0.0', '127.0.0.1', 'localhost'].includes(process.env.HOST) | ||
) { | ||
const protocol = opts.https ? 'https:' : 'http:'; | ||
return `${protocol}//${process.env.HOST}:${process.env.PORT || 8000}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
host 和 port 不能用 process.env 下的,得用 https://github.com/umijs/umi/blob/b3b956a/packages/bundler-webpack/src/dev.ts#L70-L71 这里的,框架来决定是否用 process.env 下的,所以得想办法传过来。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
虽然这个 PR 看起来并无问题了,但为了一个 socket server 变量的处理就做了一个较高级的抽象,可能这里以后都不会再有改动了,我认为是一次有些过度的抽象编码,感觉直接 if 判断是不是 socket server 可能更直接更好。 |
HMR 的 WS 地址在没直接配置 SOCKET_SERVER 环境变量时,优先与 HOST 环境变量保持一致,兜底才是当前访问地址
Summary by CodeRabbit
host
andport
options in the configuration settings.