cloudflare的kv免费已经有一段时间了,还是大佬们会玩啊。
worker+kv搭建短网址程序,github:https://github.com/xyTom/Url-Shorten-Worker/
注册cloudflare就不用多说了。
1、创建worker,部属程序。
复制粘贴:https://raw.githubusercontent.com/xyTom/Url-Shorten-Worker/main/index.js
保存并部属。
![](https://fastly.jsdelivr.net/gh/zsxwz/tuchuang@latest/2021/05/21/1cc2ddb0ed32508415972e72bed77bc1.png)
2、创建kv空间,并绑定worker。
kv名称随意,比如dwz。
![](https://fastly.jsdelivr.net/gh/zsxwz/tuchuang@latest/2021/05/21/55483b0b94469b11d9bb88134c3baf4e.png)
转到worker设置,kv命名空间绑定。变量名称是LINKS,kv命名空间就是上面创建的dwz。
![](https://fastly.jsdelivr.net/gh/zsxwz/tuchuang@latest/2021/05/21/92ec8a526abe75184ed3a73f0d3ea943.png)
一个短网址程序就搭建好了:https://short.zsxwz.workers.dev/
![](https://fastly.jsdelivr.net/gh/zsxwz/tuchuang@latest/2021/05/21/eb9b91f20b542b24c6c2f4659fa9e777.png)
3、如果需要改网站名称啥的,就fork项目,修改gh-page分支里的index.html文件
![](https://fastly.jsdelivr.net/gh/zsxwz/tuchuang@latest/2021/05/21/d8fbc4a8e16322bef1d891165c19375e.png)
修改index.html之后,然后使用jsdelivr加速一下你自己仓库的index.html。然后修改一下worker,把jsdelivr加速地址改称自己就可以了。
html= await fetch("https://fastly.jsdelivr.net/gh/xyTom/Url-Shorten-Worker@gh-pages/index.html")
好诶 学习了