GithubHelp home page GithubHelp logo

i077 / mark Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 120 KB

Private shortlinking service powered by Cloudflare Workers

Home Page: https://mark.imranh.org/5l9k

License: GNU Affero General Public License v3.0

Nix 26.61% TypeScript 52.70% JavaScript 11.48% Smarty 9.21%
cloudflare-workers serverless shortlinks

mark's Introduction

mark: A private shortlinking service

mark is a serverless shortlinking service powered by CloudFlare Workers, mostly for my own private use. The name comes from vim's marks, which let you jump to a position in a file (and is also conveniently short for bookmark). My motivation for making this was to have a short way of referring to links on paper without having to write the full URL out by hand. I also wanted a service that I was in control of, so services like bit.ly were out of the question (besides, this was pretty fun to make).

Usage

Sending a GET request to any path under https://mark.imranh.org will attempt to find a link with that path. Try it with the key EGFa!

This is a "private" service, i.e. the intent here is that only one person is generating new links (but obviously anyone can visit existing ones). To create new shortlinks, send a POST request to /new with a JSON object containing keys:

  • url: The URL to be shortened
  • authkey: A password

This will output a new four-character base62 path that can be easily written down. This only allows for around 15 million links, but that should be plenty for one person :)

How it works

Note that there is no frontend or GUI, this is meant to be as simple as possible. It's pretty easy to send POST requests from the command line, and this can be easily scripted. Below is a script I made for myself to make managing links easier: asciicast

The backend is run by CloudFlare Workers, and links are stored in Workers KV, a global eventually-consistent key-value store. GET /:key will redirect (HTTP 301) with the value of key from the KV namespace. POST /new (with the correct authkey) will write a new random base62 key to that namespace with the given link as the value.

Development

This repo uses CloudFlare's wrangler to manage development and deployment, as well as pnpm to manage Node packages. It also uses itty-router to make this easier to write.

Since the wrangler.toml file will contain account-specific info (like account & zone IDs), I use 1Password's CLI to inject these into a template file.

Future work

I'd like to add an archive function to this eventually, so webpages with different types of media can be stored and retrieved, even if the original page becomes unavailable.

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.