Skip to content
/ golink Public

A fast, open-source URL shortener with built-in QR codes and clean developer-friendly UI.

License

Notifications You must be signed in to change notification settings

dee-raj/golink

Repository files navigation

GoLink

GoLink

GoLink is a fast, minimal, developer-native URL shortener built with Next.js 14, MongoDB, and Tailwind CSS.
It’s open-source, lightweight, and comes with built-in QR code generation for every shortened link.

Features

  • Fast Redirection: Server-side redirects using Next.js route handlers.
  • Developer UI: Clean, dark aesthetic optimized for precision and readability.
  • Reliable Storage: MongoDB integration for persistent links and click tracking.
  • Slug Generation: Unique 6-character base62 slugs using nanoid.
  • API First: RESTful endpoints for shortening links and fetching metadata.
  • QR Codes: Automatically generate free QR codes for every link.
  • Download QR Code: Download QR code as PNG image.
  • New Link UX: Reset the form to create multiple links quickly.
  • Shareable: Copy, open, or share links directly from the UI.

Tech Stack

  • Framework: Next.js 14 (App Router)
  • Database: MongoDB (Mongoose)
  • Styling: Tailwind CSS
  • Icons: Lucide React
  • Slugs: Nanoid
  • QR Codes: react-qr-code

Getting Started

Prerequisites

  • Node.js 18+
  • MongoDB instance (Local or Atlas)

Environment Variables

Create a .env.local file in the root directory:

MONGODB_URI=your_mongodb_connection_string

Installation

npm install

Running Locally

npm run dev

Open http://localhost:3000 in your browser.

How Redirects Work

When a user visits /[slug], the Next.js dynamic route handler:

  1. Connects to MongoDB.
  2. Finds the originalUrl associated with the slug.
  3. Increments the clicks counter.
  4. Performs an HTTP 301 (Permanent Redirect) to the original URL.
  5. If the slug is not found, it redirects to the custom 404 page.

API Endpoints

  • POST /api/shorten: Shorten a URL.

    • Body: { "url": "https://example.com", "isNewLink": true|false }
  • GET /api/links/[slug]: Fetch metadata for a shortened URL.

  • GET /api/qrcode?slug=[slug]: Fetch QR code for a shortened link.

UI / Usage

  • Paste your long URL in the input field.
  • Click Get Link to generate a shortened URL.
  • Click Get QR Code to generate a QR code for the link.
  • Click Copy to copy the short link to your clipboard.
  • Click New Link to reset the form and generate another link.
  • Use Share to open the native sharing dialog on supported devices.
  • Use Download QR Code to download the QR code as a PNG image.

Deployment

GoLink is optimized for Vercel:

  1. Connect your GitHub repository.

  2. Set the MONGODB_URI environment variable.

  3. Deploy and your URL shortener is live.

  4. Don't forgot to give a star to GitHub

Contributing

Contributions are welcome! Please open issues or pull requests. Follow standard Next.js + Tailwind conventions for styling and code structure.

License

MIT

About

A fast, open-source URL shortener with built-in QR codes and clean developer-friendly UI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •