Giter Site home page Giter Site logo

bravo68web / cf-workers-url-shortener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 0-vortex/cf-workers-url-shortener

0.0 1.0 0.0 510 KB

Social URL links redirect service powered by Cloudflare Workers and KV. Features customizable landing page, 404 status page for missing redirects, and one-click deploy!

Home Page: http://connect-with.vortex.name

License: BSD 3-Clause "New" or "Revised" License

JavaScript 41.18% Handlebars 58.82%

cf-workers-url-shortener's Introduction

workers-url-shortener

Commitizen Friendly License FOSSA Status

Maintainability Known Vulnerabilities

Overview

A Cloudflare Workers script to use as a simple redirect system.

The data.json file can be used as dummy input or git enabled backup for your production environment.

The motivation for doing such a thing is GUI or IAM enabled acces to these variables from other CloudFlare tools, essentially promoting observability.

Folder structure

├──── workers-url-shortener
│  ├── .github/
│  ├── src/
│  ├── static/
│  ├── .editorconfig
│  ├── .eslintrc.js
│  ├── .gitattributes
│  ├── .gitignore
│  ├── .lintstagedrc.js
│  ├── .npmrc
│  ├── CODE_OF_CONDUCT.md
│  ├── LICENSE
│  ├── npm-shrinkwrap.json
│  ├── package.json
│  ├── README.md
│  └── wrangler.toml

Deploy as Cloudflare Worker

I use this service for my profile at github.com. Currently, the service is hosted on a free tier of Cloudflare Workers and limited at 100K requests per day. Make sure to make the appropriate changes in wrangler.toml first.

Deploy to Cloudflare Workers

Requirements

In order to run the project locally you need node>=14 and npm>=6.

Install @cloudflare/wrangler

Make sure you have the latest version of wrangler as described in the wrangler docs.

Updating Wrangler with NPM:

npm uninstall -g @cloudflare/wrangler && 
  npm install -g @cloudflare/wrangler 

Install with cargo

cargo install wrangler --force

Get a valid CF_API_TOKEN

Make sure you have a valid deployment token by doing:

wrangler login 

or:

wrangler config 

Generate a new repository

Create a new GitHub repository with the green button or clone:

# with git
git clone https://github.com/0-vortex/workers-url-shortener.git

or with github-cli:

# with github-cli
gh repo clone  0-vortex/workers-url-shortener

Usage

Configure KV

To successfully run the redirect worker we need to set up some KV namespaces.

Generate new namespace_ids for the KV keys it wrangler.toml and follow the instructions:

# dev environment
wrangler kv:namespace create "REDIRECTS"
wrangler kv:namespace create "REDIRECTS" --preview
# production environment
wrangler kv:namespace create "REDIRECTS" --env production
wrangler kv:namespace create "REDIRECTS" --env production --preview

After you are done editing check if the changes are correct:

wrangler kv:namespace list

Test data

Upload some data to the REDIRECTS namespace:

# dev environment
wrangler kv:bulk put --binding="REDIRECTS" ./src/data.json
wrangler kv:bulk put --binding="REDIRECTS" ./src/data.json --preview
# production environment
wrangler kv:bulk put --binding="REDIRECTS" ./src/data.json --env production
wrangler kv:bulk put --binding="REDIRECTS" ./src/data.json --env production --preview

Local development

To develop locally just run:

npm start

To deploy to dev just run:

npm run deploy

Monitoring

To monitor any of the deployed environments run:

wrangler tail

License

This library is released under BSD-3 license clause.

FOSSA Status

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.