Sign inSign up

g3rv4/simple-redirect

By g3rv4

•Updated over 9 years ago

A dirty easy to manage redirect site (I use it for my shortlinks)

Image
0

10K+

g3rv4/simple-redirect repository overview

⁠simple-redirect

An easy to use redirection script. What for? ehh... to have nice urls :D

⁠Features

  • supports multiple domains
  • exposes an endpoint to reload the URLs
  • if needed, it's able to execute a different script for each domain after the URLs are reloaded (useful if you need to invalidate a cache on a different server)
  • it integrates nicely with github and cloudflare (because well... that's exactly my use case)

⁠How it works

  1. You define your URLs either using yaml or json files and make them accessible somewhere (see my redirections file⁠ for an example... hosted by github!).
  2. You hit the /refresh endpoint for the script to load the URLs into redis
  3. If you want, it executes a script you define after the domain URLs are refreshed

⁠How I use it

  • I have a free account with cloudflare, that's caching everything to get crazy speeds
  • I store the redirections file in github
  • I set up a webhook in the github repository so that when it receives a push it hits the /refresh endpoint
    • Github has a delay before it shows the updated file version, so I set up the webhook so that it sends &wait=10. What this does is just... well, waiting 10 seconds before grabbing the file from github :)
    • I also pass &domain=gmc.uy, so that when my repository gets updated, only my script is executed
  • After the data is refreshed, I run a script that purges cloudflare's cache

⁠How to set it up

The setup is pretty straightforward, this is my docker-compose.yml

version: '2'
services:
  simple-redirect:
    image: 'g3rv4/simple-redirect'
    restart: always
    environment:
      - REDIS_HOST=localhost
      - REDIS_DB=1
      - CONFIG_FILE=/var/config/config.json
    volumes:
      - '/path/to/config:/var/config'
    ports:
      - '8000:8000'

Once you have that running, it exposes the app in the port 8000. You may probably want to put an nginx between the app server and internet. You should mount /var/config containing a configuration file... here's mine for reference

{
    "key": "thisIsACrazySecretNobodyKnows",
    "domains": {
        "gmc.uy": {
            "urls": "https://raw.githubusercontent.com/g3rv4/redirections/master/urls.json",
            "afterRefresh": "/var/config/clear-cache.sh -zone myZoneId"
        },
        "dv.uy": {
            "urls": "https://raw.githubusercontent.com/d4tagirl/redirections/master/urls.yml",
            "afterRefresh": "/var/config/clear-cache.sh -zone anotherZoneId"
        }
    }
}

and if you're running scripts (as I am) they should also go in the config folder. Feel free to check out my blog post about it⁠ :)

Tag summary

Content type

Image

Digest

Size

87.7 MB

Last updated

over 9 years ago

docker pull g3rv4/simple-redirect