A URL Shortener Powered by Cloudflare Worker with password protection feature
Introduction
Cloudflare works has 100k/day requests limistation, which is enough for a small project to use.
Steps
1. Go to Workers KV and create a namespace.
2. Create a new worker.
3. Bind an instance of a KV Namespace to access its data in this new created Worker.
4.Where Variable name should set as LINKS
and KV namespace is the namespace you just created in the first step.
LINKS
, KV namespaceå¡«åä½ ååå建çå½å空é´
5. Copy the index.js
code from this project to Cloudflare Worker.
index.js
ç代ç å°Cloudflare Worker
6. Click Save and Deploy
ç¹å»Save and DeployNote
注æï¼ç±äºè¯¥ç¤ºä¾æå¡è¢«äººæ»¥ç¨ï¼ç¨äºè½¬åè¯éªç½ç«ï¼æ ææç±demoç½ç«çæçé¾æ¥24å°æ¶åä¼èªå¨å¤±æï¼å¦éé¿æ使ç¨è¯·èªè¡æ建ã
Example Code for Authentication
This code has been put into index.html file. You might want to change it based on your needs.
<SCRIPT language="JavaScript">
var password;
var pass1="cool";
password=prompt('Please enter your password to view this page!',' ');
if (password!=pass1)
window.location="https://51sec.org";
else
{
alert('Password Correct! Click OK to enter!');
}
</SCRIPT>
Video
References
- Github project: https://github.com/51sec/Url-Shorten-By-CF-Worker
via Blogger http://blog.51sec.org/2022/06/url-shorten-serviec-powered-by.html
June 29, 2022 at 04:39PM Cloud