Code Monkey home page Code Monkey logo

stub's Introduction

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.

stub's People

Contributors

berkyzl avatar d6stiny avatar jackbailey avatar js6pak avatar renovate[bot] avatar snazzah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

stub's Issues

Better documentation for other auth methods

I'd like to request some documentation or a simple guide to how exactly we should setup each authorization method? What should I set my redirect URI as for Discord integration, etc

Appreciation!

Hey, just wanted to drop by and say thank you for starting this project!

I tried "self-hosting" dub and it is a complete nightmare right now. It depends on so many SaaS pieces that makes the open source piece kind of unworthy. I think the world could really use a truly self-hostable dub like solution, keep it up!

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency maxmind to v4.3.20
  • chore(deps): update dependency nodemailer to v6.9.14
  • chore(deps): update dependency sharp to v0.33.4
  • chore(deps): update dependency tailwindcss to v3.4.4
  • chore(deps): update dependency ua-parser-js to v1.0.38
  • chore(deps): update dependency @radix-ui/react-accordion to v1.2.0
  • chore(deps): update dependency @radix-ui/react-popover to v1.1.0
  • chore(deps): update dependency @radix-ui/react-switch to v1.1.0
  • chore(deps): update dependency @radix-ui/react-tooltip to v1.1.0
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @headlessui/react to v2
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-snazzah to v2
  • chore(deps): update dependency framer-motion to v11
  • chore(deps): update dependency typescript to v5
  • chore(deps): update dependency use-debounce to v10
  • chore(deps): update docker/build-push-action action to v6
  • chore(deps): update docker/login-action action to v3
  • chore(deps): update docker/metadata-action action to v5
  • chore(deps): update docker/setup-buildx-action action to v3
  • chore(deps): update docker/setup-qemu-action action to v3
  • chore(deps): update mailing monorepo to v1 (major) (mailing, mailing-core)
  • chore(deps): update postgres docker tag to v16
  • chore(deps): update prisma monorepo to v5 (major) (@prisma/client, prisma)
  • chore(deps): update visx monorepo to v3 (major) (@visx/axis, @visx/event, @visx/grid, @visx/responsive, @visx/shape, @visx/tooltip)
  • chore(deps): update yarn to v4
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker/docker-compose.yml
  • postgres 14-alpine
github-actions
.github/workflows/build.yml
  • actions/checkout v3
  • docker/setup-qemu-action v2
  • docker/setup-buildx-action v2
  • docker/login-action v2
  • docker/metadata-action v4
  • docker/build-push-action v3
.github/workflows/dryrun.yml
  • actions/checkout v3
  • docker/build-push-action v3
.github/workflows/lint.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @headlessui/react 1.7.17
  • @next-auth/prisma-adapter 1.0.7
  • @prisma/client 4.14.1
  • @radix-ui/react-accordion 1.1.2
  • @radix-ui/react-popover 1.0.7
  • @radix-ui/react-switch 1.0.3
  • @radix-ui/react-tooltip 1.0.7
  • @tailwindcss/forms 0.5.7
  • @visx/axis 2.18.0
  • @visx/event 2.17.0
  • @visx/grid 2.18.0
  • @visx/responsive 2.17.0
  • @visx/shape 2.18.0
  • @visx/tooltip 2.17.0
  • cookie 0.6.0
  • dotenv 16.4.5
  • focus-trap-react 10.2.3
  • framer-motion 7.10.3
  • geolite2-redist 3.0.4
  • html-escaper 3.0.3
  • ioredis 5.3.2
  • mailing 0.9.15
  • mailing-core 0.9.15
  • matcher 5.0.0
  • maxmind 4.3.18
  • ms 2.1.3
  • next 12.3.4
  • next-auth 4.24.7
  • nodemailer 6.9.13
  • prisma 4.14.1
  • react 18.2.0
  • react-colorful 5.6.1
  • react-dom 18.2.0
  • react-hot-toast 2.4.1
  • react-textarea-autosize 8.5.3
  • sharp 0.33.3
  • swr 2.2.5
  • tailwind-scrollbar-hide 1.1.7
  • tsx 4.7.2
  • ua-parser-js 1.0.37
  • use-debounce 8.0.4
  • zod 3.22.4
  • @rushstack/eslint-patch ^1.2.0
  • @tailwindcss/line-clamp 0.4.4
  • @types/cookie 0.6.0
  • @types/html-escaper 3.0.2
  • @types/minimatch 5.1.2
  • @types/ms 0.7.34
  • @types/node 20.12.5
  • @types/react 18.0.34
  • @types/react-dom 18.0.11
  • @types/ua-parser-js 0.7.39
  • autoprefixer 10.4.19
  • enquirer 2.4.1
  • eslint 8.56.0
  • eslint-config-snazzah 1.2.1
  • postcss 8.4.38
  • tailwindcss 3.4.3
  • typescript 4.9.5
  • yarn 3.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

Unable to login

When running the provided docker container with valid environment variables, and then visiting localhost:3000/login I am able to see the login page. However, entering my email, submitting and then clicking on the "Sign in" button in the received email, I simply get sent back to the login page again.

This repeats no matter what I do or change, any help would be appreciated.

Login emails not being sent

I'm running via docker compose and I setup the .env like so:
image
But when I try logging in via email, I never get the email. I got GitHub auth working, but when I set the super admin email as my GitHub email, it still doesn't give me superadmin, so I can't create any projects or start making links. Is there something I'm missing here?

iOS/Android targeting

Hi, and thanks for this great fork!

image

on app.dub.sh there is an option to specify a different link target for Android and iOS user agents, do we have any chance to get it also on stub? it'll be super useful :)

cheers

Login problem not solved.

Dear Snazzah,
.env file updated. but still email login as well as discord redirect to login page. any help?

Make links case-insensitive option per-project

Currently links are case sensitive, which may be bad for others when trying to recall links from memory, will probably force the router to lowercase the path, but would be annoying for people to switch cased links to lowercase...

Login still redirect to login page with discord

Hi all, Good Morning,
This is writing from a self taught dev. After several attempt failed to login with discord. Redirected to blank home page: My .Env
test

There some discord app oAuth2 issue: do I need to declare redirect url as http://localhost:3000/api/auth/callback/discord and what is the scope to select like email, guild, identity etc.

Email login send email but after signup redirect to login page again. not work.

Help required. Thanks in advance for your supports.

Useage without docker compose

Is it possible to run the instance through the Dockerfile provided instead of using docker compose up.

I am relatively new to hosting things directly on the web and most free hosting providers do not support docker-compose out of the box. And none seem to allow kubernetes

User Settings

Mainly to set a users name and avatar URL, may need to change stuff to not use next/image in user avatars.

Project Domain

Hi! How would I go about properly setting up a project domain? I added a CNAME record to the domain pointing to the stub domain but that doesn't seem to work.

CloudFlare DNS:
cf

Stub Project:
stub
stub

Nginx Config:
nginx

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.