Build your own Custom URL Shortener with ease
With Cloudflare Worker + GitHub Actions

A Student and Full Stack Web Developer from India with a immense knowledge of DevOps and experience in Backend APIs. Loves to contribute to Open Source.
Search for a command to run...
With Cloudflare Worker + GitHub Actions

A Student and Full Stack Web Developer from India with a immense knowledge of DevOps and experience in Backend APIs. Loves to contribute to Open Source.
Hey b ,
This is nice and interesting project; did you check Cloud flare challenge before.. may be you should give an try and make an entry
This is my First Blog. Hope you all love it.
You all must have used and heard about of bit.ly, tinyurl.com, goo.gl, etc. and often seen many websites and apps providing you short-links like t.co/xxxxx (Twitter), epi.gm/xxxx (Epic Games), etc.
When I saw them, I was very curious about them and wanted to have something of my own (it looks cool, seriously ...) .
https://go.url.me/ --> Our Base URL
https://go.url.me/github --> Link to your GitHub profile
https://go.url.me/discord --> Discord Server Invite Link
https://go.url.me/yt --> Link to you Youtube Channel
https://go.url.me/xxxx --> What ever you want ......
(Look Cool Right ...)
Let me show you how to have one of your own

Create a Cloudflare account. (If you don't have one)
Install Wrangler CLI
npm i @cloudflare/wrangler -g
Create a new Wrangler App using Template
wrangler generate <your-project-name> https://github.com/BRAVO68WEB/url-short-cfw
Output :-
Creating project called `bravo68web`...
Error: Error replacing placeholders `E:\CFW\bravo68web\.github\workflows\cfw.js.yml`
Info: caused by liquid: Unknown variable
with:
requested variable=secrets
available variables=authors, crate_name, project-name
Error: tried running command:
cmd /C C:\\Users\\Administrator\\AppData\\Local\\.wrangler\\cargo-generate-0.5.0\\cargo-generate.exe generate --git https://github.com/BRAVO68WEB/url-short-cfw --name bravo68web --force
exited with exit code: 1
(You may ignore these)
Open Your Project directory in you preferred code editor
cd your-project-name
code .
Configure Wrangler for your project
wrangler config
Output :-
╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ To find your API Token, go to https://dash.cloudflare.com/profile/api-tokens │
│ and create it using the "Edit Cloudflare Workers" template. │
│ │
│ Consider using `wrangler login` which only requires your Cloudflare username and password. │
│ │
│ If you are trying to use your Global API Key instead of an API Token │
│ (Not Recommended), run `wrangler config --api-key`. │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯
Enter API Token:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Validating credentials...
Successfully configured. You can find your configuration file at: C:\Users\Administrator\.wrangler\config\default.toml
NOTE
Copy this token somewhere as you will need it again in further steps
urls.json, which acts as a static database to store short-link names with respective URLs. Edit it as below .{
"github": "https://github.com/xxxxxx",
"yt": "https://youtube.com/watch?v=xxxxxxxxxxx",
"discord": "https://discord.gg/XXXXXXX",
"XXXXX": "https://xxxxxxxxxx.xyz",
.
.
.
}
Now, try to run your application to test whether it works or not.
wrangler dev
After code is build successfully, try to open it browser.
http://localhost:8787/
Output :-
404 not found !! Check all possible at
urls.json
Now, try to open any short link with it's name from that given in urls.json in your browser.
.
.
"test": "https://google.com",
.
.
http://localhost:8787/test
This should redirect you to https://google.com
If you are redirected to Google Homepage or what URL you have given, Congrats, 👍 it works
Now, Its's Time to Deploy


Open DNS settings and Create CNAME with name of your choice (like "go" for https://go.bravo68web.me/xxxxxx/ ") and value as Worker URL
Open wrangler.toml and edit as below
name = "<worker-name>"
type = "webpack"
account_id = "<account-id>"
workers_dev = false
route = "<subdomain.domina.id>/*"
zone_id = "<your-zone-id>"
wrangler.toml and publishwrangler publish
Now visit your https://subdomain.domain.id/xxxxx and test it.
If still everything is going good, Well Done !!!! 👍
Final Step is automation :)
You have successfully deployed you application. Now, whenever you need to add new URLs, just edit "urls.json" and push the code back to GitHub to Auto Deploy
I hope you enjoyed it !!
Thanks for Reading till the end ...
😺😺😺 Cya Soon ❤....