Categories:
Figma 国内加速的问题
利用 host 直接指定 Figma的服务器,跳过域名解析的环节。看看这个项目:
https://github.com/Moonvy/Figma-Net-OK/blob/master/app/lib/getBestHosts.js
const nslookup = require("nslookup")
const DNSServers = [
{ ip: "8.8.8.8", name: "Google DNS" },
{ ip: "180.76.76.76", name: "百度 DNS" },
{ ip: "223.5.5.5", name: "阿里 DNS", fast: true },
{ ip: "114.114.114.114", name: "114 DNS", fast: true },
{ ip: "1.1.1.1", name: "Cloudflare DNS", fast: true },
{ ip: "9.9.9.9", name: "Quad9 DNS" },
{ ip: "119.29.29.29", name: "腾讯 DNS" },
{ ip: "4.2.2.1", name: "level3.net" },
]
const Hostnames = [
{
hostname: "s3-alpha-sig.figma.com",
testUrl: "https://s3-alpha.figma.com/profile/9b3f693e-0677-4743-89ff-822b9f6b72be",
},
{
hostname: "www.figma.com",
testUrl: "https://www.figma.com/api/community_categories/all?page_size=10",
},
{
hostname: "static.figma.com",
testUrl: "https://static.figma.com/app/icon/1/icon-192.png",
},
]
/** 通过 DNS 解析域名的 IP, 返回 IP 列表 */
const server = "8.8.8.8";
Hostnames.forEach(e => {
const re = new RegExp(".");
const name = e.hostname;
nslookup(name)
.server(server) // default is 8.8.8.8
.timeout(3 * 1000) // default is 3 * 1000 ms
.end(function (err, addrs) {
if (err) {
console.log('ERROR');
} else {
// 更加易懂的写法是 new RegExp(".");
console.log(` DNS(${name} by ${server}):`, addrs.filter((x) => x && re.test(x)));
// 其中 /./ 是正则表达式,过滤掉没有点的元素
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions>
// console.log(` DNS(${name} by ${server}):`, addrs.filter((x) => x && /./.test(x)))
}
})
});
运行后的结果是
❯ node index.js
DNS(www.figma.com by 8.8.8.8): [ '13.35.202.82', '13.35.202.46', '13.35.202.119', '13.35.202.74' ]
DNS(s3-alpha-sig.figma.com by 8.8.8.8): [ '3.170.229.99', '3.170.229.52', '3.170.229.30', '3.170.229.107' ]
DNS(static.figma.com by 8.8.8.8): [ '18.155.68.46', '18.155.68.114', '18.155.68.87', '18.155.68.58' ]
然后去修改 host 文件就可以了。