Coder Social home page Coder Social logo

edba5 / url-shortener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pxeger/url-shortener

0.0 0.0 0.0 18 KB

World's simplest URL shortener using Cloudflare Workers

Home Page: https://www.pxeger.com/2020-08-06-world%27s-simplest-url-shortener-using-cloudflare-workers/

License: MIT License

JavaScript 100.00%

url-shortener's Introduction

World's Simplest URL Shortener using Cloudflare Workers

A URL Shortener is a very common proof-of-concept app to build when learning web development, and this one is nothing new. I wanted to try out Cloudflare's Workers, a super-simple Serverless platform built on their Edge Network.

If you're familiar with JavaScript Service Workers, you'll be able to write a Worker.

Here's step-by-step instructions for setting it up, also available on my blog

  1. Get a Cloudflare account and enable Workers
  2. Install wrangler, Cloudflare's CLI tool for working with Workers, and set it up using your Cloudflare API token
  3. Copy the Workers JavaScript template repository
  4. Write your code - you can see mine in index.js (don't worry, it's very simple)
  5. Create your own urls.json for mapping paths( e.g. foo for https://your-domain.com/foo) to redirect URLs.
  6. Set type to webpack in wrangler.toml (see the docs)
  7. Set your Account ID in wrangler.toml then run wrangler publish to deploy your app to a default subdomain of workers.dev
  8. To get it on your custom domain, set workers_dev to false, and zone_id in wrangler.toml to the Zone ID of your domain in Cloudflare, and route to your-domain.com/*.

This URL shortener can only have new URLs added by modifying urls.json and re-deploying. That may not be what you want, but it's perfect for me because I want mine to be private. You could look in to Cloudflare Workers KV to create a dynamic system, but for me the $5/month price floor was a little too steep for something this mundane.

Mine's deployed at pxeger.net.

url-shortener's People

Contributors

pxeger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.