Coder Social home page Coder Social logo

shrink's Introduction

Shrink

Shrinking URLs á la skill share.

This README file contains 3 main sections:

  1. Intro to Shrink
  2. Configuration
  3. Using the CLI

Introduction to Shrink

Shrink is a ver basic tool that, essentially, shrinks URLs via CLI using a REST API and MongoDB. It has two main components:

  • The API: This enables all services to shrink and redirect to source URLs.
  • The CLI: This is the official interface to access all Shrink functionality.

Available Operations

Shrink allows you to:

  • Shrink any URL: You can use the CLI with the this: command to obtain the shrunk URL. See more details in the "Using the CLI" section below.
  • Get stats from any shrunk URL (or the 'original' URL, works both ways): You can use the CLI with the stats: command.
  • Toggle on/off any shrunk URL (or the 'original' URL): You can use the CLI with the toggle: command.

Configuration

Required Configuration

All of the configuration is defaulted, but you can base on the following snippet to create a .env file with overrides to any (or all) of them:

   # Database host/port config. (Default: mongodb://localhost:27017/shrink)
   DB_HOST=mongodb://my.hosted.mongo.com:29000/shortenerdata

   # Domain of your choice (Default: shri.nk)
   DOMAIN=sho.rt

   # Port override (Default: 80)
   PORT=8080

   # Protocol (Default: http)
   PROTOCOL=https

Optional Configuration

You may want to add a line to your /etc/hosts file to have nice routing to your defined domain (see above).

CLI Configuration

Our CLI works as a node command that is executed by npm. In turn, we advise you create an alias so that it can be used with ease:

alias shrink='npm run cli'

Docker Mongo Instance

Run a local image of MongoDB to avoid installing anything:

docker pull mongo:3-xenial && docker run -d --name mongo-container -p 27017:27017 mongo:3-xenial

Using Shrink CLI

You can shrink an url by passing the command this:. NOTE: This call is idempotent, meaning that it will return on every equal request the same shrunk URL after it has been shrunk the first time.

shrink this: http://www.skillshare.com

You can also retrieve stats of the times this shrunk URL has been used by passing the stats: command.

shrink stats: http://shri.nk/emI05

Finally, your shrunk URL can be disabled temporarily, by passing the toggle: command. It will return 409 if the URL is used while disabled. This call is a switch to alternate between 'enabled' and 'disabled' status.

shrink toggle: http://www.bbc.co.uk

shrink's People

Contributors

rickbuitrago avatar rbuitragoc avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

shrink's Issues

Add a Work Queue for every unfurl request

Currently, a request to unfurl is tied to persisting stats. Make it asynchronous by adding a simple work queue that defers the stats writing and allows the redirect to occur more independently.

Handle double-shrinking

Currently, a request to shrink an already shrunk URL is served. We need to add code to validate such requests and handle gracefully.

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.