• Stars
    star
    167
  • Rank 226,635 (Top 5 %)
  • Language
    TypeScript
  • License
    GNU Affero Genera...
  • Created about 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A self-hostable modified fork of Dub: An open-source link shortener.
logo

Stub

A self-hostable modified fork of Dub: An open-source link shortener.


Introduction

Stub is a heavily modified fork of Dub: An open-source link shortener with built-in analytics using Next.js and Redis.

Warning This is still a work in progress. For a single-user instance, this works fine. User management doesn't exist yet.

Why a fork of Dub?

Dub relies a lot on serverless services (Vercel, Upstash) and wasn't all that good to self-host on your own server. There was also some hardcoded domains to dub.sh which wouldn't work when self-hosting. Stub serves to have a nice link shortener like Dub that can be hosted on your own server.

Differences

  • Stripe and Plausible modules were removed.
  • @upstash/redis was replaced with ioredis, which caused a bit of problems and I ended up restructuring link routing like in the next point.
  • Dub uses Next.js middleware to route links, but the middleware itself is limited to edge functionality, which wouldn't work for Redis outside of Upstash's Redis client (which is just calling endpoints). The router was instead made into a separate node HTTP server hosted on a separate port (default 3001). This also allows for index links with no hassle. (Using :index as a key lets you create an index link!)
  • Getting location data is different since Dub used Vercel's geolocation data. Instead, Stub will lookup geo data from GeoLite2. (Make sure that you set your trust proxy variables correctly, or else you will get a default "Userland" location!)
  • Users now have types, with users being able to be superadmins, or regular admins that can create projects. By default, users cannot create projects and will have to be invited to other projects by managers. This system is somewhat similar to Weblate.
    • Superadmins have control of instance-wide settings, like enabling or disabling new users, or limiting new users to certain e-mails. (example)
  • Stub supports more login methods other than magic link e-mails, like Discord or GitHub OAuth logins.

Tech Stack

Implementation

Stub is split into two applications, the app itself and the router. The router is a basic HTTP server that route links and handle clicks. Dub uses Next.js middleware to route links, but middleware itself is limited to edge functionality.

Redis is used as the database for storing links and analytics data, which works well for key-value data types. Redis also has the Sorted Set data type, which is perfect for storing & retrieving time-series analytics data. Here's the full schema:

  • {hostname}:{key} – string containing a JSON object with the target URL and password (optional). Also has an optional TTL.
  • {hostname}:clicks:{key} – sorted set of all clicks for a given link (e.g. dub.sh:clicks:github)

Deploy Your Own

Manual

Make sure you have Node.js v16 installed. You could install newer versions of Node, but next-auth is restricted to some versions and you will need to add --ignore-engines while installing dependencies.

You can build Stub with these commands:

git clone https://github.com/Snazzah/stub
cd stub
yarn install # --ignore-engines
yarn migrate
yarn generate
yarn build

From here, you can launch the app with yarn start and launch the router with yarn start:router. You can also start both with yarn start:all.

If you have filled in the STUB_ADMIN_EMAIL environment variable and logged in with your authentication provider of choice, you should see a shield next to your profile picture showing that you are a superadmin, and can create projects. If not, you can run yarn manage set-superadmin [email protected] to set that user with that e-mail as a superadmin.

After creating a project, you can make sure that domain is being pointed to the router's port (default 3001, can be set from ROUTER_PORT) and you can check your project settings to confirm if that domain works.

Docker

npx degit github:Snazzah/stub/docker stub-docker
cd stub-docker
# Fill out the .env variables
docker compose up -d

Upgrading docker containers

You can do this by sticking with the existing docker-compose and just pull the latest images and then restart:

# Fetch latest versions of the images
docker compose pull
# Stop and destroy the containers
docker compose down
# Spawn new containers in the background
docker compose up -d
# Follow the logs during upgrade
docker compose logs -f

Contributing

  • Open an issue if you believe you've encountered a bug.
  • Make a pull request to add new features/make quality-of-life improvements/fix bugs.

License

Just like Dub, Stub is open-source under the GNU Affero General Public License Version 3 (AGPLv3) or any later version. You can find it here.

More Repositories

1

slash-create

🗡️ Creator and handler for Discord's slash commands
TypeScript
347
star
2

duck-duck-scrape

🔎 Search from DuckDuckGo and utilize its spice APIs in Node
TypeScript
138
star
3

SublimeDiscordRP

📄 Discord rich presence for Sublime Text
Python
131
star
4

slash-create-worker

slash-create with Cloudflare Workers template
TypeScript
20
star
5

catcut

quick in-browser media editing
Svelte
20
star
6

Lightcord

A webapp for Discord Bots
JavaScript
19
star
7

PhotoBox

The bot that's all about manipulation
JavaScript
15
star
8

slash-up

💻 CLI to view Discord commands and sync commands with slash-create
TypeScript
15
star
9

slash-create-vercel

Deploy a slash-create server to Vercel.
HTML
12
star
10

MediaSessionMaster

Utilize Chrome's MediaSession API within multiple sites.
JavaScript
10
star
11

HotImage

🎴 Easy-to-use application that turns folders into image API
HTML
9
star
12

slash-create-template

A template for running slash commands on a webserver.
JavaScript
9
star
13

magic-stopwatch

✨⏱️ A light and pause-able stopwatch node module
TypeScript
7
star
14

ducksearch

Search with DuckDuckGo in Discord and utilize it's API.
TypeScript
7
star
15

botsgg-widget

Cloudflare worker for bots.gg widgets.
TypeScript
6
star
16

DiscordVid2

Port of twitter bot this__vid3: The objectively best Discord video downloader.
JavaScript
5
star
17

TrelloBot

Old Trello Bot V1 code, new one @ tacobot.app
JavaScript
4
star
18

YOMIRecord

A mod for Your Only Move Is Hustle that allows you to record and screenshot replays.
GDScript
4
star
19

VideoEmbedFix

Fix embeds for some services in Discord and Telegram
TypeScript
4
star
20

xban

A simple slash-command bot that cross-bans users.
TypeScript
4
star
21

snazzah.com

My own website. Wow!
Astro
4
star
22

steam.exposed

Breakdowns of Steam's Year in Reviews
Svelte
4
star
23

DiscordInjections-Chrome

Chrome extension for Discord Injections
JavaScript
3
star
24

typescript-env

My TypeScript environment for most projects.
TypeScript
3
star
25

BotBoy.rb

A Discord bot that is connected to a lot of API endpoints.
Ruby
3
star
26

Godot2Discord

Connect to Discord in Godot with no need for GDNative
GDScript
2
star
27

davey

work-in-progress Discord DAVE implementation in TypeScript
TypeScript
2
star
28

badapple.mov

bad apple.
HTML
2
star
29

Snazzah

My own README.md
2
star
30

Faux

Simple and powerful Discord bot engine
JavaScript
2
star
31

TweetDiff

Open a diff checker for edited tweets.
TypeScript
2
star
32

hackrice13

Manage feedback forms from large communities! (For HackRice13)
Python
2
star
33

weeb.rb

A rubygem wrapper for weeb.sh
Ruby
1
star
34

LightcordExtension

The browser extension for Lightcord
JavaScript
1
star
35

Turquoise

Universal Discord OAuth Gate
JavaScript
1
star
36

BeautifulDiscordSnippets

Cool things to inject into discord
CSS
1
star
37

Discord.FM-Widget

A desktop/web widget for now playing information.
HTML
1
star
38

tgClassy

A wrapper for the Telegram Bot API
JavaScript
1
star
39

hackmud_env

A workspace to build and minify your scripts.
JavaScript
1
star
40

slash-create-website

The website and documentation for slash-create
Vue
1
star
41

Better-Discord-Themes

CSS
1
star
42

TrelloWebhookAPI

Webhook reciever API for Trello Bot
JavaScript
1
star
43

Tadpole

A Discord bot that connects to multiple channels
Ruby
1
star
44

Open-API-Endpoints

API endpoints that anyone can use for their next project!
1
star
45

kekbot

Discord meme trading bot
Ruby
1
star