chore: Felo 相关脚本

This commit is contained in:
2026-09-10 10:48:32 +08:00
parent 168fc28d48
commit b9682de64a
2 changed files with 172 additions and 0 deletions
+172
View File
@@ -0,0 +1,172 @@
// 公司官网检测链接跳转和有效性的脚本
const http = require('http');
const https = require('http');
const locale = 'zh-TW';
const homeUrl = 'http://localhost:3003';
// const homeUrl = 'https://felo.me';
const urls = [
{
url: `${homeUrl}`,
code: 307,
comment: '跳转-首页',
location: `/translator`,
},
{
url: `${homeUrl}/zh-TW`,
code: 307,
comment: '跳转-仅语言',
location: `/zh-TW/translator`,
},
{
url: `${homeUrl}/en`,
code: 307,
comment: '跳转-仅语言-默认',
location: `/translator`,
},
{
url: `${homeUrl}/en`,
code: 307,
comment: '跳转-仅语言-双参数相同',
location: `/translator`,
headers: {
'accept-language': 'en-US',
},
},
{
url: `${homeUrl}/en`,
code: 307,
comment: '跳转-仅语言-双参数不相同 A',
location: `/translator`,
headers: {
'accept-language': 'zh-TW',
},
},
{
url: `${homeUrl}/ja`,
code: 307,
comment: '跳转-仅语言-双参数不相同 B',
location: `/ja/translator`,
headers: {
'accept-language': 'zh-TW',
},
},
{
url: `${homeUrl}/translator`,
code: 200,
comment: '无跳转-业务-默认语言',
},
{
url: `${homeUrl}/translator`,
code: 200,
comment: '无跳转-业务-Headers语言-同默认语言',
headers: {
'accept-language': 'en-US',
},
},
{
url: `${homeUrl}/translator`,
code: 307,
location: '/ru/translator',
comment: '跳转-业务-Headers语言-非默认语言',
headers: {
'accept-language': 'ru',
},
},
{
url: `${homeUrl}/en/translator`,
code: 307,
location: '/translator',
comment: '跳转-业务-地址栏语言-默认',
},
{
url: `${homeUrl}/id/translator`,
code: 200,
comment: '无跳转-业务-地址栏语言-非默认',
},
{
url: `${homeUrl}/zh-TW/translator`,
code: 200,
comment: '无跳转-业务-双参数不相同 A',
headers: {
'accept-language': 'ja',
},
},
{
url: `${homeUrl}/it/translator`,
code: 200,
comment: '无跳转-业务-双参数不相同 B',
headers: {
'accept-language': 'zh-CN',
},
},
{
url: `${homeUrl}/ja-JP`,
code: 307,
comment: '临时跳转-jaJP-首页',
location: '/ja/translator',
},
{
url: `${homeUrl}/ja-JP/translator`,
code: 307,
comment: '临时跳转-jaJP-业务',
location: '/ja/translator',
headers: {
'accept-language': 'zh-CN',
},
},
];
const promises = urls.map((item, index) => {
const url = new URL(item.url);
return new Promise((resolve, reject) => {
const options = {
hostname: url.hostname,
port: url.port,
method: 'GET',
path: url.pathname,
headers: item.headers,
};
http.get(options, (res) => {
let chunkRes;
res.on('data', (chunk) => {
chunkRes = chunk.toString();
})
res.on('end', () => {
const urlItem = urls[index];
const status = res.statusCode;
resolve({
comment: urlItem.comment,
url: urlItem.url,
status: status === urlItem.code ? '✅' : '❌',
// statusShould: urlItem.code,
statusActual: status,
location: urlItem.location ? (
urlItem.location === res.headers.location ? '✅' : '❌'
) : '/',
// locationShould: urlItem.location || '',
locationActual: res.headers.location || '',
});
});
res.on('error', (err) => {
console.log(err, item.url);
reject();
})
}).on('error', (err) => {
console.log('err', err);
});
});
});
Promise.all(promises).then(async (res) => {
console.table(res);
});