From 4ff5188040650f1f90eeac8aad6eb7edf6c065c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Tue, 18 Jun 2024 23:50:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=AC=E5=8F=B8=E5=AE=98=E7=BD=91?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E9=93=BE=E6=8E=A5=E8=B7=B3=E8=BD=AC=E5=92=8C?= =?UTF-8?q?=E6=9C=89=E6=95=88=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 fetch 拿不到 location 头,改成 https 实现 --- homepage-rewrite-test.js | 140 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 homepage-rewrite-test.js diff --git a/homepage-rewrite-test.js b/homepage-rewrite-test.js new file mode 100644 index 0000000..ca394d0 --- /dev/null +++ b/homepage-rewrite-test.js @@ -0,0 +1,140 @@ +// 公司官网检测链接跳转和有效性的脚本 + +const https = require('https'); + +const homeUrl = 'https://felo.me'; +const meetUrl = 'https://meet.felo.me'; +const imUrl = 'https://im.felo.me'; + +const urls = [ + // 301 检测 + { + url: `${homeUrl}/meeting`, + code: 301, + comment: '跳转检测', + location: `${meetUrl}/`, + }, + { + url: `${homeUrl}/pricing`, + code: 301, + comment: '跳转检测', + location: `${meetUrl}/pricing`, + }, + // { + // url: `${homeUrl}/download`, + // code: 301, + // comment: '跳转检测(可不做', + // location: `${meetUrl}/download`, + // }, + // { + // url: `${homeUrl}/contact`, + // code: 301, + // comment: '跳转检测(可不做', + // location: `${meetUrl}/contact`, + // }, + // { + // url: `${homeUrl}/security`, + // code: 301, + // comment: '跳转检测(可不做', + // location: `${imUrl}/security`, + // }, + + // Meet + { + url: `${meetUrl}/contact`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '联系我们', + }, + { + url: `${meetUrl}/zh-TW/contact`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '联系我们(限定语言)', + }, + { + url: `${meetUrl}/pricing`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '收费', + }, + { + url: `${meetUrl}/zh-TW/pricing`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '收费(限定语言)', + }, + { + url: `${meetUrl}/download`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '下载', + }, + { + url: `${meetUrl}/zh-TW/download`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '下载(限定语言)', + }, + { + url: `${meetUrl}/home`, + code: 200, + matcher: /You need to enable/, + comment: '会议首页' + }, + + // IM + { + url: `${imUrl}/security`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '安全', + }, + { + url: `${imUrl}/zh-TW/security`, + code: 200, + matcher: /\/homepage\/umi.js/, + comment: '安全(限定语言)', + }, +]; + +const promises = urls.map((item, index) => { + return new Promise((resolve, reject) => { + https.get(item.url, (res) => { + let chunkRes; + + res.on('data', (chunk) => { + chunkRes = chunk.toString(); + }) + + res.on('end', () => { + const urlItem = urls[index]; + const status = res.statusCode; + + resolve({ + url: urlItem.url, + status: status === urlItem.code ? '匹配' : '不匹配', + statusShould: urlItem.code, + statusActual: status, + locationShould: urlItem.location || '/', + locationActual: res.headers.location || '/', + location: urlItem.location ? ( + urlItem.location === res.headers.location ? '匹配' : '不匹配' + ) : '/', + match: urlItem.matcher ? ( + chunkRes.match(urlItem.matcher) ? '内容匹配' : '内容不匹配' + ) : '/', + comment: urlItem.comment, + }); + }); + + res.on('error', () => { + reject(); + }) + }); + }); +}); + +Promise.all(promises).then(async (res) => { + console.table(res); +});