【白嫖攻略】自建短链服务

【白嫖攻略】自建短链服务

无服务器,自建短链服务,Url-Shorten-Worker修改为自用 - 完整的部署教程
源码 GitHub: https://github.com/crazypeace/Url-Shorten-Worker

申请Cloudflare账号,略。
创建一个KV
记得这个KV的名字,以 urlsrv 为例

查看此KV

添加一个条目Entry
密钥key为password,值value为一个随机字符串.

  • password这个key是在脚本中要引用的,所以要设置这个。

随机字符串可以使用http://git.io/xkcdpw生成

随机字符串以 yejiandianci 为例

创建Worker服务

设置绑定KV

变量名称必须设置为 LINKS, KV的名字选刚刚创建的 urlsrv

  • LINKS 是在脚本中要引用的,所以要设置这个。换句话说,如果你使用别的脚本,可能这个变量名称就不是LINKS了。

编辑Worker的脚本


把原有的内容全部删掉

换成:https://github.com/crazypeace/Url-Shorten-Worker/blob/main/index.js 的内容
保存并部署

======

要访问 你的worker域名/yejiandianci 来打开使用页面

如:https://snowy-disk-fd82.ciys.workers.dev/yejiandianci

======

后记
你可以通过在你自己的域名下worker页面添加一个路由指向worker的方式来实现比如 1ladder.eu.org/z487DD 替代 snowy-disk-fd82.ciys.workers.dev/z487DD 的效果。

如果你想使用原版,worker里面的脚本使用 https://github.com/xyTom/Url-Shorten-Worker/blob/main/index.js 的内容

======

开发记录
直接访问域名返回404。在KV中设置一个entry,保存秘密path,只有访问这个path才显示使用页面。

https://zelikk.blogspot.com/2022/07/url-shorten-worker-hide-tutorial.html

支持自定义短链

https://zelikk.blogspot.com/2022/07/url-shorten-worker-custom.html

API 不公开服务

https://zelikk.blogspot.com/2022/07/url-shorten-worker-api-password.html

页面缓存设置过的短链

https://zelikk.blogspot.com/2022/08/url-shorten-worker-localstorage.html

长链接文本框预搜索localStorage

https://zelikk.blogspot.com/2022/08/url-shorten-worker-bootstrap-list-group-oninput.html

增加删除某条短链的按钮

https://zelikk.blogspot.com/2022/08/url-shorten-worker-delete-kv-localstorage.html