// 公司官网检测链接跳转和有效性的脚本 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); });