surgioproject / surgio

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

程序化配置文件 #279

Open liblaf opened 1 month ago

liblaf commented 1 month ago

希望能够将 surgio 作为第三方库使用, 例如:

import { defineClashProvider } from "surgio";
import { getProvider } from "surgio/provider";

const provider = await getProvider(
  "NAME",
  defineClashProvider({ url: "https://example.com" }),
);
console.log(provider.getNodeList());

但得到了如下错误:

50 | };
51 | exports.loadConfig = loadConfig;
52 | const getConfig = () => {
53 |     // istanbul ignore next
54 |     if (!finalConfig) {
55 |         throw new Error('请先调用 loadConfig 方法');
                   ^
error: 请先调用 loadConfig 方法
      at getConfig (***/node_modules/surgio/build/config.js:55:15)
      at new Provider (***/node_modules/surgio/build/provider/Provider.js:59:26)
      at new ClashProvider (***/node_modules/surgio/build/provider/ClashProvider.js:25:9)
      at ***/node_modules/surgio/build/provider/index.js:44:20
      at getProvider (***/node_modules/surgio/build/provider/index.js:26:28)
      at ***/hello.ts:4:24

Bun v1.1.21 (Linux x64)

https://github.com/surgioproject/surgio/blob/7bc53d4e3531b2eeced3f9f91e3ce9320b25523c/src/config.ts#L20-L61

注意到 loadConfig() 需要从文件系统中读取 surgio.conf.js 并保存在 finalConfig 中. 是否可以允许程序化设置 finalConfig 而无需 surgio.conf.js 文件?

geekdada commented 3 weeks ago

请问这么做是要实现什么功能?

liblaf commented 3 weeks ago

请问这么做是要实现什么功能?

@geekdada 我希望在 serverless (例如 cf worker) 上部署代理规则生成器, 我希望能够复用 surgio 部分代码.