url-shortener-redis Svelte Themes

Url Shortener Redis

A simple url shortener written in Go and svelte

URL Shortener

A simple URL Shortener built using:

Features

āœ… Shorten long URLs with a custom alias (optional)
āœ… Fast and lightweight using Redis for storage
āœ… Simple API with rate-limiting
āœ… Fully containerized for easy deployment

A Take Away

To Change Your App's Domain During Development, Modify The .env File in ./api

šŸ› ļø Setup & Installation

Prerequisites

Ensure you have Docker and Docker Compose installed.

Running the Application

To build and run the application, execute:

docker-compose up -d

This will:

  • Build and start the frontend, backend, and Redis containers.
  • Expose the frontend on http://localhost:5173.
  • Expose the backend on http://localhost:3000.

To stop the application:

docker-compose down

šŸ“‚ Project Structure

ā”œā”€ā”€ frontend/       # Svelte + Vite frontend
ā”œā”€ā”€ backend/        # Go Fiber backend
ā”œā”€ā”€ docker-compose.yml  # Docker Compose config for the project
|── db              # Location Of Dockerfile Configuration For Redis
└── README.md       # This file

šŸ”— API Endpoints

Shorten a URL

POST /api/shorten

{
  "url": "https://example.com",
  "short": "{ your own custom short }" // Its Optional, You Can Omit This
}

Typical Response:

{
  "url": "https://example.com",
  "short": "http://localhost:3000/myalias",
  "expiry": 3600,
  "rate-limit": 9,
  "rate-limit-reset": 60
}

Redirect to Original URL

GET /{short_url}


šŸ› ļø Development

For local development:

  1. Frontend
    cd frontend
    npm install
    npm run dev
    
  2. Backend
    cd backend
    go mod tidy
    go run main.go
    
  3. Redis (if running locally)
    docker run --name redis -p 6379:6379 -d redis
    

šŸš€ Deployment

To deploy using Docker Compose:

docker-compose up -d --build

This will run the services in detached mode (-d).


šŸ“œ License

This project is licensed under the MIT License.


šŸ™ Acknowledgements

I would like to acknowledge Akhil Sharma for the wonderful tutorial series on golang and redis.


šŸ¤ Contributing

Feel free to submit issues or PRs to improve this project!

Top categories

Loading Svelte Themes