Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 2.33 KB

README.md

File metadata and controls

44 lines (33 loc) · 2.33 KB

puhack.horse

🔗🐴 A link shortener powered by Vercel Edge Config.

This is a monorepo with two repositories:

  • dash
    • An admin dashboard with an optimistic UI
  • horse
    • Middleware that handles redirecting

Story

A little while back we made the original puhack.horse, which used Airtable as a source of truth. This worked great for us, but we thought it could be even faster if it didn't have to leave the Edge to get its data.

It turns out it's a lot faster! But we lose Airtable, and we have non-technical people on our team who want to be able to super easily edit routes—so the dash repo is an admin dashboard that allows for super easy editing of routes using the SWR Mutation API.

Screenshot 2023-02-25 at 3 22 12 AM

Deploy

  • Create a GitHub OAuth app (Settings –> Developer Settings). Set the callback URL to YOUR_DOMAIN/api/auth/callback/github.
  • Create an Edge Config Store on your Vercel Dashboard.
  • Clone this repo.
  • In dash/lib/auth.ts, comment out the line with isInOrg() at the bottom, or replace it with your own function. This is used to restrict signup to a group of people (in our case, we only want people in our GitHub org to manage routes).
  • Deploy the project to Vercel. You'll have to create two projects: one for the horse folder and one for the dash folder.
  • Set the following environment variables in the dash project:
    • NEXT_PUBLIC_HORSE_SECRET
    • EDGE_CONFIG_ID
    • TEAM_ID
    • VERCEL_API_TOKEN
    • GITHUB_CLIENT_SECRET
    • GITHUB_CLIENT_ID
    • NEXTAUTH_URL
    • NEXTAUTH_SECRET
    • GH_ACCESS_TOKEN
  • Set the following environment variable in the horse project:
    • HORSE_SECRET
  • Connect the Edge Config Store you created to both projects in their "Edge Config" settings tabs.
  • profit!

Note: Edge Config is great but not meant to be used for a serious link shortener. The free plan only allows for 8KB of data, which you'll use up after ~100 routes.