fix: 用 js-yaml 正确解析 config.yaml 获取 dashboard token
替换正则提取方式,使用 js-yaml 解析 YAML 文件, 通过 config.gateway.auth.token 和 config.gateway.port 读取字段。 Made-with: Cursor
This commit is contained in:
10
lib/frpc.js
10
lib/frpc.js
@@ -25,6 +25,7 @@ const TTYD_PORT = 7681;
|
||||
* systemd 服务的 ProtectHome=read-only 允许读取 /home 下的文件。
|
||||
*/
|
||||
function getDashboardInfo() {
|
||||
const yaml = require('js-yaml');
|
||||
const configCandidates = [
|
||||
path.join(os.homedir(), '.openclaw', 'config', 'config.yaml'),
|
||||
'/home/sts/.openclaw/config/config.yaml',
|
||||
@@ -33,11 +34,10 @@ function getDashboardInfo() {
|
||||
|
||||
for (const cfgPath of configCandidates) {
|
||||
try {
|
||||
const raw = fs.readFileSync(cfgPath, 'utf8');
|
||||
const tokenMatch = raw.match(/^\s*token:\s*["']?([A-Za-z0-9_\-\.]+)["']?\s*$/m);
|
||||
const portMatch = raw.match(/^\s*port:\s*(\d+)\s*$/m);
|
||||
const token = tokenMatch?.[1];
|
||||
const port = portMatch ? Number(portMatch[1]) : 18789;
|
||||
const raw = fs.readFileSync(cfgPath, 'utf8');
|
||||
const config = yaml.load(raw);
|
||||
const token = config?.gateway?.auth?.token;
|
||||
const port = config?.gateway?.port || 18789;
|
||||
if (token) {
|
||||
log.info('dashboard', `从配置文件读取: port=${port}, token=${token.substring(0, 8)}...`);
|
||||
return Promise.resolve({ dashboard_port: port, dashboard_token: token });
|
||||
|
||||
Reference in New Issue
Block a user