Shell-Scripts/homepage-rewrite-test.js

192 lines
4.0 KiB
JavaScript

// 公司官网检测链接跳转和有效性的脚本
const https = require('https');
const locale = 'zh-TW';
const homeUrl = 'https://felo.me';
const meetUrl = 'https://meet.felo.me';
const imUrl = 'https://im.felo.me';
// const homeUrl = 'https://home-dev.felo.me';
// const meetUrl = 'https://meet-dev.felo.me';
// const imUrl = 'https://im-dev.felo.me';
const urls = [
// 301 检测
{
url: `${homeUrl}/meeting`,
code: 301,
comment: '跳转检测',
location: `${meetUrl}/`,
},
{
url: `${homeUrl}/pricing`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/${locale}/pricing`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/security`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/${locale}/security`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/translator`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/${locale}/translator`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/download`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/${locale}/download`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/contact`,
code: 200,
comment: '不跳转检测',
},
{
url: `${homeUrl}/${locale}/contact`,
code: 200,
comment: '不跳转检测',
},
// Meet
{
url: `${meetUrl}`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '会议首页,命中官网',
},
{
url: `${meetUrl}/home`,
code: 200,
matcher: /You need to enable/,
comment: '会议系统,命中系统'
},
{
url: `${meetUrl}/contact`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '联系我们',
},
{
url: `${meetUrl}/${locale}/contact`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '联系我们(限定语言)',
},
{
url: `${meetUrl}/pricing`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '收费',
},
{
url: `${meetUrl}/${locale}/pricing`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '收费(限定语言)',
},
{
url: `${meetUrl}/download`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '下载',
},
{
url: `${meetUrl}/${locale}/download`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '下载(限定语言)',
},
// IM
{
url: `${imUrl}/security`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '安全',
},
{
url: `${imUrl}/${locale}/security`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '安全(限定语言)',
},
{
url: `${imUrl}/contact`,
code: 200,
matcher: /\/homepage\/umi.js/,
comment: '安全',
},
{
url: `${imUrl}/${locale}/contact`,
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', (err) => {
console.log(err, item.url);
reject();
})
});
});
});
Promise.all(promises).then(async (res) => {
console.table(res);
});