Skip to content

mathzds/shorturl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShortURL

ShortURL is a URL shortening service built with Fastify, TypeScript, and MongoDB. It allows users to shorten long URLs and retrieve the original URLs using the shortened versions.

Features

  • Generate short URLs for long URLs.
  • Redirect to the original URL using the short URL.
  • MongoDB for persistent storage.

Prerequisites

  • Node.js (v16 or later)
  • Docker (for MongoDB setup)
  • TypeScript

Setup Instructions

  1. Clone the repository:

    git clone <repository-url>
    cd shorturl
  2. Install dependencies:

    npm install
  3. Set up MongoDB:

    • Ensure Docker is installed and running.
    • Start MongoDB using Docker Compose:
      docker-compose up -d
  4. Configure environment variables:

    • Update the .env file if necessary. The default values are:
      MONGO_URI=mongodb://root:example@localhost:27017
      PORT=1234
      
  5. Run the development server:

    npm run dev
  6. Access the application:

    • The server will be running at http://localhost:1234/api.

API Endpoints

POST /shorten

  • Description: Create a short URL for a given original URL.
  • Request Body:
    {
      "originalUrl": "https://example.com"
    }
  • Response:
    {
      "_id": "unique-id",
      "originalUrl": "https://example.com",
      "shortUrl": "short-id"
    }

GET /:shortUrl

  • Description: Redirect to the original URL using the short URL.
  • Response:
    • 302 Redirect to the original URL if found.
    • 404 if the short URL does not exist.

Project Structure

shorturl/
├── src/
│   ├── common/
│   │   ├── models/         # Mongoose models
│   │   └── types/          # TypeScript type definitions
│   ├── core/               # Core application logic
│   ├── modules/            # Services and routes
│   └── index.ts            # Application entry point
├── .env                    # Environment variables
├── docker-compose.yml      # MongoDB setup
├── tsconfig.json           # TypeScript configuration
└── package.json            # Project metadata and scripts

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors