无服务器 自建短链服务 Url-Shorten-Worker 完整的部署教程

源码 GitHub https://github.com/crazypeace/Url-Shorten-Worker

演示站 https://urlsrv.crazypeace.workers.dev/bodongshouqulveweifengci


申请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/worker.js 的内容

保存并部署


======

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

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

======

后记

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


======

配置参数的作用

const config = {
  result_page: false, // After get the value from KV, if use a page to show the result.
  theme: "", // Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" .
  cors: true, // Allow Cross-origin resource sharing for API requests.
  unique_link: false, // 一个长链是否只有唯一的短链(会增加写入的使用量)
  custom_link: true, // 允许自定义短链
  snapchat_mode: false, // 短链只能访问一次(访问后就删除了)
  visit_count: true, // 使用记数(会大大增加写入的使用量, 多人共用不推荐打开)
  load_kv: false, // 从KV加载全部数据(自用推荐打开, 多人共用会看到别人的数据) 
  system_type: "shorturl", // shorturl, pastebin, imghost,
}

======

如果要当网络记事本 PasteBin

演示站 https://pastebin.crazypeace.workers.dev/tieludasiliqiuweiyue

演示视频 https://www.youtube.com/watch?v=toBeb3DNpZc


======

如果要当图床 Image Hosting

演示站 https://imghost.crazypeace.workers.dev/imghostimghost

演示视频 https://www.youtube.com/watch?v=B7wH4tB1-O8



======

如果要当网络日记本, 支持MarkDown

演示站 https://journal.crazypeace.workers.dev/journaljournal

演示视频 https://www.youtube.com/watch?v=DZcXqyIm_R0

https://www.youtube.com/watch?v=Ra6SXZFeGM8



======

如果要做一次性二维码

演示站 https://snapchat.crazypeace.workers.dev/huiyingebielianaiputi


======

开发记录

直接访问域名返回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

访问计数功能 可查询短链 成为功能完整的短链API系统

https://zelikk.blogspot.com/2023/11/url-shorten-worker-visit-count-api-api.html

阅后即焚功能, 可制作一次性二维码

https://zelikk.blogspot.com/2023/11/url-shorten-worker-snapchat-mode.html

增加读取 KV 中全部记录的功能

https://zelikk.blogspot.com/2024/01/url-shorten-worker-load-cloudflare-kv.html

变身网络记事本 Pastebin

https://zelikk.blogspot.com/2024/01/url-shorten-worker-pastebin.html

变身图床 Image Hosting

https://zelikk.blogspot.com/2024/01/url-shorten-worker-image-hosting-base64.html

变身日记本 NetJournal 支持Markdown

https://zelikk.blogspot.com/2024/02/url-shorten-worker-netjournal.html

https://zelikk.blogspot.com/2024/02/url-shorten-worker-netjournal-markdown.html

https://zelikk.blogspot.com/2024/04/url-shorten-worker-netjournal-markdown.html


评论

The Hot3 in Last 30 Days