-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使twikoo支持Cloudflare worker的兼容性改动 #695
Conversation
与 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢贡献。
因为twikoo-func被多个部署方式所依赖,而本改动没有考虑其他部署方式,所以该PR的改动必然会带来问题。
cloudflare worker除了和JSDOM存在兼容性问题,是否还和其他第三方依赖存在兼容性问题?如果只是JSDOM,建议减小改动范围,只提取JSDOM。
如果您能确定cloudflare worker和哪些第三方依赖存在兼容问题,我可以完成其他部署方式的修改和测试。 |
目前确认如下模块与Cloudflare worker存在兼容性问题:
参见:https://github.com/Tao-VanJS/twikoo-cloudflare?tab=readme-ov-file#known-limitations 现在这个PR和nodemailer的整合是有一点问题的,我现在正在修复。修好了会合并到这个PR里。 |
考虑一下 #696 这个方案是否能满足您的需求:将lib.js其中的第三方依赖统统包装成get方法: lib.js module.exports = {
getCheerio() {
const $ = require('cheerio') // jQuery 服务器版
return $
},
getAkismetClient() {
const { AkismetClient } = require('akismet-api') // 反垃圾 API
return AkismetClient
},
getCryptoJS() {
const CryptoJS = require('crypto-js') // 编解码
return CryptoJS
},
getFormData() {
const FormData = require('form-data') // 图片上传
return FormData
},
getAxios() {
const axios = require('axios') // 发送 REST 请求
return axios
},
getBowser() {
const bowser = require('bowser') // UserAgent 格式化
return bowser
},
getDomPurify() {
// 初始化反 XSS
const { JSDOM } = require('jsdom') // document.window 服务器版
const createDOMPurify = require('dompurify') // 反 XSS
const window = new JSDOM('').window
const DOMPurify = createDOMPurify(window)
return DOMPurify
},
getIpToRegion() {
const ipToRegion = require('@imaegoo/node-ip2region') // IP 属地查询
return ipToRegion
},
getMarked() {
const marked = require('marked') // Markdown 解析
return marked
},
getMd5() {
const md5 = require('blueimp-md5') // MD5 加解密
return md5
},
getNodemailer() {
const nodemailer = require('nodemailer') // 发送邮件
return nodemailer
},
getPushoo() {
const pushoo = require('pushoo').default // 即时消息通知
return pushoo
},
getTencentcloud() {
const tencentcloud = require('tencentcloud-sdk-nodejs') // 腾讯云 API NODEJS SDK
return tencentcloud
},
getXml2js() {
const xml2js = require('xml2js') // XML 解析
return xml2js
}
} 这样,当twikoo-cloudflare依赖lib.js时,就不会因立即加载DOMPurify而报错了 |
仅在需要时导入第三方依赖,避免某一个依赖出现兼容性问题而无法导入其他依赖。
const logger = require('./logger') | ||
|
||
let tencentcloud | ||
|
||
function getTencentCloud () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个getTencentCloud
是不是和getTencentcloud
名字太过接近了😁?
这个PR包含了所有支持Cloudflare worker的兼容性改动。部署Cloudflare worker的源代码在这里:https://github.com/Tao-VanJS/twikoo-cloudflare ,亲测有效。
根据实测结果,相比Netlify/Vercel + MongoDB的部署,Cloudflare worker的部署把冷启动的页面加载时间从6秒左右降到了小于0.5秒,极大地提升了用户体验。