surgioproject / surgio

Generating rules for Surge, Clash, Quantumult like a PRO
https://surgio.js.org
MIT License
1.62k stars 138 forks source link

【BUG】网关模式与命令行模式生成结果不一致 #270

Closed X1A0CA1 closed 6 months ago

X1A0CA1 commented 6 months ago

环境: @surgio/gateway: 2.0.1 surgio: 3.8.1 node: 22.0.0 npx: 10.5.1 npm: 10.5.1 yarn: 1.22.22 pnpm: 9.0.6

已经在 surgio.conf.js 启用了 clash.meta 支持。

clashConfig: {
    clashCore: "clash.meta"
  }, 

测试模板如下:

rules:
{% filter clash %}
DOMAIN,test.com,REJECT
DOMAIN-SUFFIX,test.com,REJECT
DOMAIN-KEYWORD,test.com,REJECT
DOMAIN-REGEX,test.com,REJECT
GEOSITE,test.com,REJECT
GEOIP,test.com,REJECT
SRC-GEOIP,test.com,REJECT
IP-ASN,test.com,REJECT
SRC-IP-ASN,test.com,REJECT
IP-CIDR,test.com,REJECT
IP-CIDR6,test.com,REJECT
SRC-IP-CIDR,test.com,REJECT
IP-SUFFIX,test.com,REJECT
SRC-IP-SUFFIX,test.com,REJECT
SRC-PORT,test.com,REJECT
DST-PORT,test.com,REJECT
IN-PORT,test.com,REJECT
DSCP,test.com,REJECT
PROCESS-NAME,test.com,REJECT
PROCESS-PATH,test.com,REJECT
PROCESS-NAME-REGEX,test.com,REJECT
PROCESS-PATH-REGEX,test.com,REJECT
NETWORK,test.com,REJECT
UID,test.com,REJECT
IN-TYPE,test.com,REJECT
IN-USER,test.com,REJECT
IN-NAME,test.com,REJECT
SUB-RULE,test.com,REJECT
AND,test.com,REJECT
OR,test.com,REJECT
NOT,test.com,REJECT
RULE-SET,test.com,REJECT
MATCH,test.com,REJECT
{% endfilter %}

当使用 npx surgio generate 时,输出是预期行为,包含了当前代码版本中 clash.meta 所支持的所有分流规则,如下:

rules:
- DOMAIN,test.com,REJECT
- DOMAIN-SUFFIX,test.com,REJECT
- DOMAIN-KEYWORD,test.com,REJECT
- GEOSITE,test.com,REJECT
- GEOIP,test.com,REJECT
- IP-CIDR,test.com,REJECT
- IP-CIDR6,test.com,REJECT
- SRC-IP-CIDR,test.com,REJECT
- IP-SUFFIX,test.com,REJECT
- SRC-IP-SUFFIX,test.com,REJECT
- SRC-PORT,test.com,REJECT
- DST-PORT,test.com,REJECT
- IN-PORT,test.com,REJECT
- DSCP,test.com,REJECT
- PROCESS-NAME,test.com,REJECT
- PROCESS-PATH,test.com,REJECT
- NETWORK,test.com,REJECT
- UID,test.com,REJECT
- IN-TYPE,test.com,REJECT
- IN-USER,test.com,REJECT
- IN-NAME,test.com,REJECT
- SUB-RULE,test.com,REJECT
- AND,test.com,REJECT
- OR,test.com,REJECT
- NOT,test.com,REJECT
- RULE-SET,test.com,REJECT
- MATCH,test.com,REJECT

但当使用网关模式,也就是 node server.js 启动服务器,通过网页 (get-artifact/clash.yaml)下载/预览的文件只包含了:

rules:
- DOMAIN,test.com,REJECT
- DOMAIN-SUFFIX,test.com,REJECT
- DOMAIN-KEYWORD,test.com,REJECT
- GEOIP,test.com,REJECT
- IP-CIDR,test.com,REJECT
- IP-CIDR6,test.com,REJECT
- SRC-IP-CIDR,test.com,REJECT
- SRC-PORT,test.com,REJECT
- DST-PORT,test.com,REJECT
- PROCESS-NAME,test.com,REJECT
- MATCH,test.com,REJECT

猜测: 仅从网关模式的输出结果来看,仅包含了 clash 支持的分流规则,并没有包含 clash.meta 的任何一条分流规则,可能是在网关模式下并没有成功读取到 clashConfig.clashCore 所导致的问题? js 很菜,不会看代码,只能靠猜,见谅

geekdada commented 6 months ago

请检查一下你的 gateway 版本,2.2.0 已经支持读取这个配置了,不过 gateway 仅支持从 surgio.conf.js 中读取,节点一层会被忽略。