|
GoLink is a fast, minimal, developer-native URL shortener built with Next.js 14, MongoDB, and Tailwind CSS. |
- 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.
- Framework: Next.js 14 (App Router)
- Database: MongoDB (Mongoose)
- Styling: Tailwind CSS
- Icons: Lucide React
- Slugs: Nanoid
- QR Codes:
react-qr-code
- Node.js 18+
- MongoDB instance (Local or Atlas)
Create a .env.local file in the root directory:
MONGODB_URI=your_mongodb_connection_stringnpm installnpm run devOpen http://localhost:3000 in your browser.
When a user visits /[slug], the Next.js dynamic route handler:
- Connects to MongoDB.
- Finds the
originalUrlassociated with theslug. - Increments the
clickscounter. - Performs an HTTP 301 (Permanent Redirect) to the original URL.
- If the slug is not found, it redirects to the custom 404 page.
-
POST /api/shorten: Shorten a URL.- Body:
{ "url": "https://example.com", "isNewLink": true|false }
- Body:
-
GET /api/links/[slug]: Fetch metadata for a shortened URL. -
GET /api/qrcode?slug=[slug]: Fetch QR code for a shortened link.
- 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.
GoLink is optimized for Vercel:
-
Connect your GitHub repository.
-
Set the
MONGODB_URIenvironment variable. -
Deploy and your URL shortener is live.
Contributions are welcome! Please open issues or pull requests. Follow standard Next.js + Tailwind conventions for styling and code structure.