From a4c5c962c2350aae1aaa320e52a7792ba4dc8742 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 3 Jun 2023 18:25:18 +0800 Subject: [PATCH] fix #9 --- scripts/make_dev_link.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/make_dev_link.js b/scripts/make_dev_link.js index 392f734..26e3df7 100644 --- a/scripts/make_dev_link.js +++ b/scripts/make_dev_link.js @@ -1,4 +1,5 @@ import fs from 'fs'; +import http from 'node:http'; import readline from 'node:readline'; @@ -19,11 +20,34 @@ let POST_HEADER = { "Content-Type": "application/json", } +async function myfetch(url, options) { + //使用 http 模块,从而兼容那些不支持 fetch 的 nodejs 版本 + return new Promise((resolve, reject) => { + let req = http.request(url, options, (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + resolve({ + ok: true, + status: res.statusCode, + json: () => JSON.parse(data) + }); + }); + }); + req.on('error', (e) => { + reject(e); + }); + req.end(); + }); +} + async function getSiYuanDir() { let url = 'http://127.0.0.1:6806/api/system/getWorkspaces'; let conf = {}; try { - let response = await fetch(url, { + let response = await myfetch(url, { method: 'POST', headers: POST_HEADER });