Skip to content

yehezkielgunawan/shortin-v3-rev

Repository files navigation

Shortin - URL Shortener

A minimalist, responsive, and accessible URL shortener service built with Hono JS and Tailwind CSS, deployed on Cloudflare Workers.

License Hono Tailwind CSS

✨ Features

  • πŸ”— URL Shortening - Shorten long URLs instantly with auto-generated or custom short codes
  • πŸ“‹ Copy to Clipboard - One-click copy for generated short URLs
  • πŸ“± QR Code Generation - Generate downloadable QR codes for your shortened URLs
  • πŸ“Š Visit Statistics - Track how many times your shortened links have been clicked
  • β™Ώ Accessible (a11y) - WCAG 2.1 compliant with screen reader support, keyboard navigation, and reduced motion support
  • πŸ“± Responsive Design - Beautiful UI that works on all devices
  • ⚑ Edge Deployed - Runs on Cloudflare Workers for ultra-fast global performance
  • πŸ”„ Smart Redirects - 2-second loading screen with countdown before redirect

πŸ› οΈ Tech Stack

Technology Purpose
Hono Ultra-fast web framework
Tailwind CSS v4 Utility-first CSS framework
Vite Build tool and dev server
Cloudflare Workers Edge deployment platform
Vitest Unit testing framework
qrcode QR code generation
Plus Jakarta Sans Typography

πŸš€ Getting Started

Prerequisites

Installation

# Clone the repository
git clone https://github.com/yehezkielgunawan/shortin-v3-rev.git
cd shortin-v3-rev

# Install dependencies
pnpm install

Development

# Start development server on port 3000
pnpm dev

The app will be available at http://localhost:3000

Testing

# Run tests in watch mode
pnpm test

# Run tests once (CI mode)
pnpm test:ci

# Run tests with coverage report
pnpm test:coverage

Build & Deploy

# Build for production
pnpm build

# Preview production build locally
pnpm cf:preview

# Deploy to Cloudflare Workers
pnpm cf:deploy

Type Generation

Generate/synchronize types based on your Worker configuration:

pnpm cf-typegen

πŸ“– Usage

Shortening a URL

  1. Enter your long URL in the input field
  2. (Optional) Add a custom short code
  3. Click "Shorten URL"
  4. Copy the generated short URL

Generating a QR Code

  1. After shortening a URL, click the "Generate QR Code" button
  2. The QR code will be displayed with the shortened URL below it
  3. Click "Download QR Code" to save it as a PNG image

Accessing a Shortened URL

Visit https://shortin-api.yehezgun.com/{shortCode} to be redirected to the original URL.

πŸ”Œ API Reference

The app proxies requests to the backend API through /api/* routes.

Create Short URL

POST /api/shorten
Content-Type: application/json

{
  "url": "https://www.example.com/some/long/url",
  "shortCodeInput": "custom-code"  // optional
}

Response (201)

{
  "id": "id_1620000000000_1234",
  "url": "https://www.example.com/some/long/url",
  "shortCode": "custom-code",
  "createdAt": "2024-01-01T00:00:00.000Z",
  "updatedAt": "2024-01-01T00:00:00.000Z",
  "count": 0
}

Get Original URL

GET /api/{shortCode}

Response (200)

{
  "url": "https://www.example.com/some/long/url"
}

Get Visit Statistics

GET /api/{shortCode}/stats

Response (200)

{
  "count": 42
}

Update Destination URL

PUT /api/{shortCode}
Content-Type: application/json

{
  "url": "https://www.example.com/new/url"
}

Response (200)

{
  "message": "Short code updated successfully"
}

Delete Short URL

DELETE /api/{shortCode}

Response (200)

{
  "message": "Short code deleted successfully"
}

Error Responses

Status Response
400 { "error": "URL is required" }
400 { "error": "Short code already in use" }
404 { "error": "Short code not found" }
500 { "error": "Failed to shorten URL" }

πŸ“ Project Structure

shortin-v3-rev/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ client/           # Client-side hydration scripts
β”‚   β”‚   β”œβ”€β”€ main.tsx      # Main page hydration
β”‚   β”‚   └── redirect.tsx  # Redirect page hydration
β”‚   β”œβ”€β”€ components/       # JSX Components
β”‚   β”‚   β”œβ”€β”€ ShortenForm.tsx
β”‚   β”‚   └── RedirectPage.tsx
β”‚   β”œβ”€β”€ lib/              # Shared utilities
β”‚   β”‚   β”œβ”€β”€ formReducer.ts
β”‚   β”‚   └── qrcode.ts     # QR code generation utility
β”‚   β”œβ”€β”€ test/             # Test files
β”‚   β”‚   β”œβ”€β”€ setup.ts
β”‚   β”‚   β”œβ”€β”€ index.test.ts
β”‚   β”‚   └── formReducer.test.ts
β”‚   β”œβ”€β”€ index.tsx         # Main Hono app & routes
β”‚   β”œβ”€β”€ renderer.tsx      # HTML renderer
β”‚   └── style.css         # Global styles
β”œβ”€β”€ public/               # Static assets
β”œβ”€β”€ dist/                 # Build output
β”œβ”€β”€ vite.config.ts        # Vite configuration
β”œβ”€β”€ vitest.config.ts      # Vitest configuration
β”œβ”€β”€ wrangler.jsonc        # Cloudflare Workers config
└── package.json

β™Ώ Accessibility Features

This app is built with accessibility in mind:

  • Semantic HTML - Proper use of <main>, <article>, <header>, <footer> landmarks
  • ARIA Labels - Screen reader-friendly labels and live regions
  • Keyboard Navigation - Skip links and proper focus management
  • Color Contrast - WCAG AA compliant color contrast ratios
  • Reduced Motion - Respects prefers-reduced-motion user preference
  • High Contrast Mode - Supports prefers-contrast: high media query
  • Form Accessibility - Proper labels, error announcements, and validation messages

πŸ”§ Environment Variables

Configure the following in your Cloudflare Workers environment:

Variable Description Default
API_ENDPOINT Backend API URL https://shortin-api.yehezgun.com

πŸ“œ Scripts Reference

Script Description
pnpm dev Start development server
pnpm build Build for production
pnpm test Run tests in watch mode
pnpm test:ci Run tests once
pnpm test:coverage Run tests with coverage
pnpm cf:preview Preview production build
pnpm cf:deploy Deploy to Cloudflare Workers
pnpm cf-typegen Generate Cloudflare types
pnpm up-latest Update all dependencies

πŸ“„ License

This project is open-source and available under the MIT License.

πŸ™ Acknowledgments


Made with ❀️ by Yehezkiel Gunawan

About

A rewrite version of previous Shortin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors