Преглед изворни кода

chore: more detailed about dashboard inet6 option

Zhongwen Deng пре 3 година
родитељ
комит
5c08c4ff4e

+ 3 - 3
apps/emqx_dashboard/i18n/emqx_dashboard_i18n.conf

@@ -74,8 +74,8 @@ Note: `sample_interval` should be a divisor of 60."""
   }
   inet6 {
     desc {
-      en: "Enable IPv6 support."
-      zh: "启用IPv6"
+      en: "Enable IPv6 support, default is false, which means IPv4 only."
+      zh: "启用IPv6, 如果机器不支持IPv6,请关闭此选项,否则会导致仪表盘无法使用。"
     }
     label {
       en: "IPv6"
@@ -85,7 +85,7 @@ Note: `sample_interval` should be a divisor of 60."""
   ipv6_v6only {
     desc {
       en: "Disable IPv4-to-IPv6 mapping for the listener."
-      zh: "禁用IPv4-to-IPv6映射"
+      zh: "当开启 inet6 功能的同时禁用 IPv4-to-IPv6 映射。该配置仅在 inet6 功能开启时有效。"
     }
     label {
       en: "IPv6 only"

+ 15 - 2
apps/emqx_dashboard/src/emqx_dashboard.erl

@@ -185,8 +185,21 @@ ranch_opts(Options) ->
         socket
     ],
     RanchOpts = maps:with(Keys, Options),
-    SocketOpts = maps:fold(fun filter_false/3, [], maps:without([enable | Keys], Options)),
-    RanchOpts#{socket_opts => SocketOpts}.
+    SocketOpts = maps:fold(
+        fun filter_false/3,
+        [],
+        maps:without([enable, inet6, ipv6_v6only | Keys], Options)
+    ),
+    InetOpts =
+        case Options of
+            #{inet6 := true, ipv6_v6only := true} ->
+                [inet6, {ipv6_v6only, true}];
+            #{inet6 := true, ipv6_v6only := false} ->
+                [inet6];
+            _ ->
+                [inet]
+        end,
+    RanchOpts#{socket_opts => InetOpts ++ SocketOpts}.
 
 filter_false(_K, false, S) -> S;
 filter_false(K, V, S) -> [{K, V} | S].