Open Shorts

simple. lightweight, lightning fast

Open source URL shortener

Url Shortener

Enter the url you would like to have shortened

Captcha Field
Documentation
start/routes.js 'use strict' /** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */ const Route = use('Route') Route.get('/shorts', 'CaptchaController.ShortIndex') Route.get('/s/:id', 'ShortController.GetShort') Route.post('/shorts', 'ShortController.PostShort') Route.get('/captcha/:ts', 'CaptchaController.GetCaptcha') Route.on('/').render('welcome')
Routes

    There are 3 routes specifically related to openShorts.

  • /shorts - GET route to display the single view for openShorts
  • /shorts - POST route to verify the captcha and create a short link
  • /s/:id - GET route that looks up the short link as referenced by :id. If link exists, simply redirects user to original url.
Controller

    There are two controller methods specifically related to openShorts.

  • PostShort - Handles the form submission, verifies the captcha and returns a response. If the captcha is correct, the entered url is assigned a unique id and entered into a Redis store. If the captcha does not match, the user is shown an error message.
  • GetShort - Pulls the id off of the query string and checks it against the store. If the id is valid, the long url is returned and the user is transparently redirected.
Screenshot showing code for the OpenShorts Controller in NodeJS