The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update docs
Steven Teyfb9212820f4c
diff --git a/apps/docs/local-development.mdx b/apps/docs/local-development.mdxindex cb3d1020c6..d821797de5 100644--- a/apps/docs/local-development.mdx+++ b/apps/docs/local-development.mdx@@ -1,7 +1,7 @@---title: "Local Development""og:title": "How to setup Dub.co for Local Development (6 steps)"-description: "A guide on how to run Dub's codebase locally."+description: "A guide on how to run Dub.co's codebase locally."---## Introduction@@ -60,135 +60,211 @@ Here's the code that powers link redirects:## Running Dub locally-### Prerequisites--Before you begin, make sure you have the following:+To run Dub.co locally, you'll need to set up the following:- A [Tinybird](https://www.tinybird.co/) account- An [Upstash](https://upstash.com/) account- A [Planetscale](https://planetscale.com/) account-In the future, we plan to make it easier to self-host Dub.co by making these dependencies optional by swapping them out for native databases (e.g. mysql, redis, clickhouse, [GeoLite2](https://github.com/GitSquared/node-geolite2-redist) etc.)+### Step 1: Local setup-Also, Docker is currently not supported, but we have a few [open](https://github.com/dubinc/dub/issues/25) [issues](https://github.com/dubinc/dub/issues/378) and [PRs](https://github.com/dubinc/dub/pull/391) for it.+<Steps>-### Step 1: Local setup+ <Step title="Clone the repo">-First, clone the [Dub repo](https://dub.sh/github)+First, clone the [Dub.co repo](https://dub.sh/github) into a public GitHub repository.-```bash-git clone https://github.com/dubinc/dub.git-```+ ```bash+ git clone https://github.com/dubinc/dub.git+ ```-Run the following command to install the dependencies:+ </Step>-```bash-pnpm i-```+ <Step title="Install dependencies">-Install Mintlify CLI (for docs server):+ Run the following command to install the dependencies:-```bash-pnpm i -g mintlify-```+ ```bash+ pnpm i+ ```-Convert the `.env.example` file to `.env`:+ </Step>-```bash-cp apps/web/.env.example apps/web/.env-```+ <Step title="Optional: Install Mintlify">-You can start filling in the first few environment variables:+ If you're planning to make changes to [Dub.co's Docs](/docs), you'll need to install the [Mintlify CLI](https://mintlify.com/docs/development) to build the documentation site.-```bash-# The domain that your app will be hosted on-NEXT_PUBLIC_APP_DOMAIN=http://localhost:8888-# The short domain that your app will be using (could be the same as the above)-NEXT_PUBLIC_APP_SHORT_DOMAIN=dub.localhost:8888-```+ ```bash+ pnpm install -g mintlify+ ```-You will fill in the remaining environment variables in the following steps.+ </Step>-### Step 2: Publish Tinybird endpoints+</Steps>-Next, you'll need to publish the Tinybird endpoints:+### Step 2: Set up Tinybird database-1. In your [Tinybird](https://tinybird.co/) account, create a new Workspace.-2. Copy your `admin` [Auth Token](https://www.tinybird.co/docs/concepts/auth-tokens.html). Paste this token as the `TINYBIRD_API_KEY` environment variable in your `.env` file.-3. In your cloned Dub repo, navigate to the `packages/tinybird` directory.-4. Install the Tinybird CLI with `pip install tinybird-cli` (requires Python >= 3.8).-5. Run `tb auth` and paste your `admin` Auth Token.-6. Run `tb push` to publish the datasource and endpoints in the `packages/tinybird` directory. You should see the following output (truncated for brevity):+Next, you'll need to set up Tinybird for the analytics database:-```bash-$ tb push--** Processing ./datasources/click_events.datasource-** Processing ./endpoints/clicks.pipe-...-** Building dependencies-** Running 'click_events'-** 'click_events' created-** Running 'device'-** => Test endpoint at https://api.us-east.tinybird.co/v0/pipes/device.json-** Token device_endpoint_read_8888 not found, creating one-** => Test endpoint with:-** $ curl https://api.us-east.tinybird.co/v0/pipes/device.json?token=p.ey...NWeaoTLM-** 'device' created-...-```+<Steps>++ <Step title="Create Tinybird Workspace">++ In your [Tinybird](https://tinybird.co/) account, create a new Workspace.++ Copy your `admin` [Auth Token](https://www.tinybird.co/docs/concepts/auth-tokens.html). Paste this token as the `TINYBIRD_API_KEY` environment variable in your `.env` file.++ </Step>++ <Step title="Install Tinybird CLI and authenticate">++In your newly-cloned Dub.co repo, navigate to the `packages/tinybird` directory.++ Install the Tinybird CLI with `pip install tinybird-cli` (requires Python >= 3.8).++ Run `tb auth` and paste your `admin` Auth Token.++ </Step>++ <Step title="Publish Tinybird datasource and endpoints">++ Run `tb push` to publish the datasource and endpoints in the `packages/tinybird` directory. You should see the following output (truncated for brevity):++ ```bash+ $ tb push++ ** Processing ./datasources/click_events.datasource+ ** Processing ./endpoints/clicks.pipe+ ...+ ** Building dependencies+ ** Running 'click_events'+ ** 'click_events' created+ ** Running 'device'+ ** => Test endpoint at https://api.us-east.tinybird.co/v0/pipes/device.json+ ** Token device_endpoint_read_8888 not found, creating one+ ** => Test endpoint with:+ ** $ curl https://api.us-east.tinybird.co/v0/pipes/device.json?token=p.ey...NWeaoTLM+ ** 'device' created+ ...+ ```++ </Step>++ <Step title="Set up Tinybird API base URL">++ You will then need to update your [Tinybird API base URL](https://www.tinybird.co/docs/api-reference/api-reference.html#regions-and-endpoints) to match the region of your database.++ From the previous step, take note of the **Test endpoint** URL. It should look something like this:++ ```+ Test endpoint at https://api.us-east.tinybird.co/v0/pipes/device.json+ ```++ Copy the base URL and paste it as the `TINYBIRD_API_URL` environment variable in your `.env` file.++ ```bash+ TINYBIRD_API_URL=https://api.us-east.tinybird.co+ ```++ </Step>++</Steps>### Step 3: Set up Upstash Redis databaseNext, you'll need to set up the Upstash Redis database:-1. In your [Upstash account](https://console.upstash.com/), create a new database.-2. For better performance & read times, we recommend setting up a global database with several read regions.+<Steps>++ <Step title="Create Upstash database">++In your [Upstash account](https://console.upstash.com/), create a new database.++For better performance & read times, we recommend setting up a global database with several read regions.-3. Once your database is created, copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from the **REST API** section into your `.env` file.+ </Step>++ <Step title="Set up Upstash Redis environment variables">++Once your database is created, copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from the **REST API** section into your `.env` file.-4. Navigate to the [QStash tab](https://console.upstash.com/qstash) and copy the `QSTASH_TOKEN`, `QSTASH_CURRENT_SIGNING_KEY`, and `QSTASH_NEXT_SIGNING_KEY` from the **Request Builder** section into your `.env` file.+Navigate to the [QStash tab](https://console.upstash.com/qstash) and copy the `QSTASH_TOKEN`, `QSTASH_CURRENT_SIGNING_KEY`, and `QSTASH_NEXT_SIGNING_KEY` from the **Request Builder** section into your `.env` file.+ </Step>++ <Step title="Optional: Set up Ngrok tunnel">++ If you're planning to run Qstash-powered background jobs locally, you'll need to set up an Ngrok tunnel to expose your local server to the internet.++ Follow [these steps](https://ngrok.com/docs/getting-started/) to setup `ngrok`, and then run the following command to start an Ngrok tunnel at port `8888`:++ ```bash+ ngrok http 8888+ ```++ Copy the `https` URL and paste it as the `NGROK_URL` environment variable in your `.env` file.++ </Step>++</Steps>+### Step 4: Set up Planetscale database-In your [Planetscale account](https://app.planetscale.com/), create a new database. You can use the free tier for this project.+Next, you'll need to set up the Planetscale MySQL database:-Once your database is created, you'll be prompted to select your language or Framework. Select **Prisma**.+<Steps>-+ <Step title="Create Planetscale database">-Then, you'll have to create a new password for your database. Once the password is created, scroll down to the **Add credentials to .env** section and copy the `DATABASE_URL` into your `.env` file.+ In your [Planetscale account](https://app.planetscale.com/), create a new database. You can use the free tier for this project.-+ Once your database is created, you'll be prompted to select your language or Framework. Select **Prisma**.-Going back to your terminal, navigate to the `apps/web` directory and run the following command to generate the Prisma client:+ -```bash-npx prisma generate-```+ </Step>-Then, create the database tables with the following command:+ <Step title="Set up Planetscale environment variables">-```bash-npx prisma db push-```+ Then, you'll have to create a new password for your database. Once the password is created, scroll down to the **Add credentials to .env** section and copy the `DATABASE_URL` into your `.env` file.++ ++ </Step>++ <Step title="Generate Prisma client and create database tables">++ In the terminal, navigate to the `apps/web` directory and run the following command to generate the Prisma client:++ ```bash+ npx prisma generate+ ```++ Then, create the database tables with the following command:++ ```bash+ npx prisma db push+ ```++ </Step>++</Steps>### Step 5: Set up GitHub OAuth-Next, follow [these steps](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps) to create a GitHub App. This will let you sign in to Dub with your GitHub account.+Next, follow [these steps](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps) to create a GitHub App. This will allow you to sign in to Dub.co with your GitHub account.-Don't forget to set this Callback URLs `http://localhost:8888/api/auth/callback/github` for local development.+Don't forget to set the following Callback URL:-<Info>- Optional: Set the "Email addresses" account permission to **read-only** in- order to access private email addresses on GitHub.-</Info>+```+http://localhost:8888/api/auth/callback/github+```Once your GitHub App is created, copy the `Client ID` and `Client Secret` into your `.env` file as the `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` environment variables.@@ -200,4 +276,4 @@ Finally, you can start the development server. This will build the packages + stpnpm dev```-The Web app will be available at [http://localhost:8888](http://localhost:8888) and the Docs will be available at [http://localhost:3334](http://localhost:3334).+The web app (`apps/web`) will be available at [localhost:8888](http://localhost:8888) and the docs (`apps/docs`) will be available at [localhost:3334](http://localhost:3334).diff --git a/apps/docs/self-hosting.mdx b/apps/docs/self-hosting.mdxindex 2b46334985..1d78daf99a 100644--- a/apps/docs/self-hosting.mdx+++ b/apps/docs/self-hosting.mdx@@ -131,6 +131,24 @@ In your newly-cloned Dub.co repo, navigate to the `packages/tinybird` directory.</Step>+ <Step title="Set up Tinybird API base URL">++ You will then need to update your [Tinybird API base URL](https://www.tinybird.co/docs/api-reference/api-reference.html#regions-and-endpoints) to match the region of your database.++ From the previous step, take note of the **Test endpoint** URL. It should look something like this:++ ```+ Test endpoint at https://api.us-east.tinybird.co/v0/pipes/device.json+ ```++ Copy the base URL and paste it as the `TINYBIRD_API_URL` environment variable in your `.env` file.++ ```bash+ TINYBIRD_API_URL=https://api.us-east.tinybird.co+ ```++ </Step>+</Steps>## Step 3: Set up Upstash Redis database@@ -220,7 +238,7 @@ Next, follow [these steps](https://docs.github.com/en/apps/oauth-apps/building-oDon't forget to set the following Callback URLs:-- `https://app.yourdomain.com/api/auth/callback/github`+- `https://app.acme.com/api/auth/callback/github`- `http://localhost:8888/api/auth/callback/github` for local development.<Info>@@ -275,7 +293,7 @@ Once you've set up all of the above services, you can now deploy your app to VerIn the **Environment Variables** section, add all of the environment variables from your `.env` file by copying all of them and pasting it into the first input field. A few notes:- Remove the `PROJECT_ID_VERCEL` environment variable for now since we will only get the project ID after deploying the project.- - Replace the `NEXTAUTH_URL` environment variable with the app domain that you will be using (e.g. `https://app.yourdomain.com`).+ - Replace the `NEXTAUTH_URL` environment variable with the app domain that you will be using (e.g. `https://app.acme.com`).Click on **Deploy** to deploy your project.@@ -301,7 +319,7 @@ Add both the `NEXT_PUBLIC_APP_DOMAIN` and `NEXT_PUBLIC_APP_SHORT_DOMAIN` as doma<Step title="Redeploy your Vercel project">Go back to the **Deployments** page and redeploy your project.- Once the deployment is complete, you should be able to visit your app domain (e.g. `https://app.yourdomain.com`) and see the following login page:+ Once the deployment is complete, you should be able to visit your app domain (e.g. `https://app.acme.com`) and see the following login page:diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex 1e1557a8f4..4fa1052d9b 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -9,6 +9,8 @@ NEXT_PUBLIC_APP_SHORT_DOMAIN=dub.sh# Tinybird – required for analytics# Get your Tinybird Auth Token here: https://www.tinybird.co/docs/concepts/auth-tokens.htmlTINYBIRD_API_KEY=+# Varies based on your Tinybird region: https://www.tinybird.co/docs/api-reference/api-reference.html#regions-and-endpoints+TINYBIRD_API_URL=https://api.us-east.tinybird.co# Vercel's Domains API – required for adding and removing domains# Learn how to set this up: https://vercel.com/templates/next.js/domains-api@@ -85,7 +87,7 @@ CLOUDINARY_URL=DUB_SLACK_HOOK_CRON=DUB_SLACK_HOOK_LINKS=-# Used for local testing+# Used for background jobs# Get your ngrok URL here: https://ngrok.com/NGROK_URL=diff --git a/apps/web/lib/analytics.ts b/apps/web/lib/analytics.tsindex 029f8bc94f..023c441f1c 100644--- a/apps/web/lib/analytics.ts+++ b/apps/web/lib/analytics.ts@@ -134,7 +134,7 @@ export const getAnalytics = async ({}let url = new URL(- `https://api.us-east.tinybird.co/v0/pipes/${endpoint}.json`,+ `${process.env.TINYBIRD_API_URL}/v0/pipes/${endpoint}.json`,);if (projectId) {url.searchParams.append("projectId", projectId);diff --git a/apps/web/lib/tinybird.ts b/apps/web/lib/tinybird.tsindex 8ad304e1fc..aab69d2ef9 100644--- a/apps/web/lib/tinybird.ts+++ b/apps/web/lib/tinybird.ts@@ -46,7 +46,7 @@ export async function recordClick({return await Promise.allSettled([fetch(- "https://api.us-east.tinybird.co/v0/events?name=dub_click_events&wait=true",+ `${process.env.TINYBIRD_API_URL}/v0/events?name=dub_click_events&wait=true`,{method: "POST",headers: {@@ -112,7 +112,7 @@ export async function recordLink({deleted?: boolean;}) {return await fetch(- "https://api.us-east.tinybird.co/v0/events?name=dub_links_metadata&wait=true",+ `${process.env.TINYBIRD_API_URL}/v0/events?name=dub_links_metadata&wait=true`,{method: "POST",headers: {