Skip to content

PIKACHUIM/CFWorkerUrls

Repository files navigation

Cloudflare Worker Short URL Server 短链接服务

利用Cloudflare Worker搭建一个无需服务器的短链接服务,支持:

  1. 缩短您的网址URL,使它更容易书写或者点击访问
  2. STUN服务器NAT端口转发,您无需公网IP即可使用
  3. 支持API自动更新链接,支持到期自动删除

Build a server free short link service using Cloudflare Worker, supporting:

  1. Shorten your website URL to make it easier to write or click to access
  2. STUN server NAT port forwarding, you don't need a public IP to use it
  3. Support API automatic link update and automatic link deletion upon expiration

Demo: https://1web.us.kg/

Usages / 部署方式

Clones / 克隆代码

git clone https://github.com/PIKACHUIM/CFWorkerUrls.git
cd CFWorkerUrls
npm install
cp wrangler.toml.example wrangler.toml

Config / 修改配置

修改wrangler.toml的内容

  • account_id: 登录cloudflare,在workers-and-pages查看
  • FULL_URL: 完整服务访问地址,比如https://1web.us.kg/
  • id: 登录cloudflare-存储与数据库-KV-新建数据库查看ID
account_id = "******************************"
FULL_URL= "https://*********/"
id = "*****************************"

Deploy / 部署云端

wrangler login
wrangler deploy

Lucky Webhook

  • 请求类型:POST
  • 请求地址:https://1web.us.kg/p/
{
  "suffix": "网站后缀",
  "tokens": "更新密码",
  "typing": "http",
  "ipaddr": "{ip}",
  "porter": "{port}"
}

网站后缀和更新密码:https://1web.us.kg/

自定义路径

修改wrangler.toml文件:

...
[vars]
EDIT_SUB=true # <--- set true
EDIT_LEN=8
...

Frontend / 前端开发与构建

新版前端基于 React 18 + Vite + Ant Design 5 重构,源码位于 frontend/ 目录,构建产物输出到根目录 public/,由 wrangler.toml 中的 [site] bucket = "./public" 静态托管。

安装依赖

npm run install-fe
# 等价于 cd frontend && npm install

开发模式

启动 wrangler 后端 + Vite 前端(建议两个终端):

# 终端 1:启动 Cloudflare Worker 后端
npm run dev-cf

# 终端 2:启动前端开发服务器(默认 5173 端口)
npm run dev-fe

Vite 已配置代理,将 /u/q/p/s/b/t 等接口请求转发到 http://127.0.0.1:8787(wrangler dev 默认端口)。

生产构建

npm run build-fe

构建会在 public/ 下生成:index.htmllinks.htmllogin.htmlerror.htmlassets/ 静态资源。原版 HTML 已备份至 public/legacy/ 以便回滚。

部署

deploy-cfdeploy-eo 已自动串联前端构建:

npm run deploy-cf   # 等价于 npm run build-fe && wrangler deploy ...

Releases

No releases published

Packages

 
 
 

Contributors