Skip to content

This repo contains all the code related to the app - Shortly.

Notifications You must be signed in to change notification settings

yash6318/shortly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shortly - a URL Shortener app

This project is called Shortly, a URL shortener application with a frontend built using React and a backend built using Go. The backend uses PostgreSQL as the database.

Features

  • Shorten long URLs
  • Redirect short URLs to their original destinations
  • Health check endpoints
  • Dockerized setup for easy deployment

Setup

Development Environment

  1. Clone the repository:

    git clone https://github.com/yash6318/shortly.git
    cd shortly
  2. Create a .env file in the url-shortener-backend directory:

    DB_HOST=db
    DB_PORT=5432
    DB_USER=postgres
    DB_PASSWORD=yourpassword
    DB_NAME=shortener
    BASE_URL=http://localhost:8080
  3. Run the application using Docker Compose:

    docker-compose up --build
  4. Access the application:

Production Environment

  1. Create a .env file in the url-shortener-backend directory:

    DB_HOST=db
    DB_PORT=5432
    DB_USER=postgres
    DB_PASSWORD=yourpassword
    DB_NAME=shortener
    BASE_URL=http://localhost:8080
  2. Run the application using Docker Compose with production configuration:

    docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
  3. Access the application:

Docker Hub Images

If you prefer to use pre-built Docker images from Docker Hub, you can use the following configuration: (beware of major changes in env variables)

version: "3.9"

services:
  app:
    image: yash6318/shortly-backend:allorg
    ports:
      - "8080:8080"
    environment:
      - DB_HOST=db
      - DB_PORT=5432
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_NAME=${DB_NAME}
      - BASE_URL=http://localhost:8080
      - CORS_ALLOWED_ORIGINS=http://your-production-frontend.com
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 10s
      timeout: 5s
      retries: 3
  
  frontend:
    image: yash6318/shortly-frontend:allorg
    ports:
      - "3000:3000"
    environment:
      - REACT_APP_API_URL=http://localhost:8080
    depends_on:
      app:
        condition: service_healthy
  
  db:
    image: postgres:15
    container_name: postgres-db
    environment:
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_NAME}
    ports:
      - "5432:5432"
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "${DB_USER}", "-d", "${DB_NAME}"]
      interval: 10s
      retries: 5
      timeout: 5s

volumes:
  db-data:

This setup will allow users to run the application in both development and production environments using Docker Compose.

About

This repo contains all the code related to the app - Shortly.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published