Giter Club home page Giter Club logo

shortener's Introduction

A URL Shortener

This is a repository for a simple URL shortener web application. The JavaScript (JS) app takes any URL and a returns a shortened version in the form of a unique file path served by this resource. When visiting the shortened version of the URL, the user is redirected to the original (lengthy) URL. Additionally, if a URL has already been shortened by the system, and it is entered a second time, the first shortened URL should be given back to the user.

Prerequisites

  • git distributed version control system
  • Node JavaScript runtime

Built With Partial "MERN" Stack

  • Node
  • Express web application framework, for handling and creating URLs
  • create-react-app a boilerplate version of React: a component based user interface JS library
  • JSON-Server a fake REST API to handle data

Front end caveats:

  • This is a very simple, single view app with minimal components. Using React for the front end is a bit overkill. If I had time, I would look for a more lightweight solution.
  • Because this is a small project, no CSS frameworks, preprocessor, or component library was developed. Although that would be best approach for most control and minimal footprint. For this project, I picked PureCSS for a lightweight, responsive styling framework promising compatibility across browsers.

Express Routes

The Express app uses two endpoints: /long for posting long URLs and checking if they already exist, and /:short for calling up the corresponding long URL, and performing the redirect (if the long URL exists).

Installation

As this is a demonstration exercise, not meant to be production-ready, this implementation is bypassing installation of a genuine database component. Database funcitonality is being mocked up JSON-Server API using a single JSON file to represent the data layer.

File Structure:

The file structure of this app is logically divided to represent three separate pieces that could conceptually run standalone (on separate servers). Performant apps should implement this kind of separation so that these parts of the system can handle many connections simultaneously on their own without bogging each other down.

 mockDb
 |-- db.json   <--- Mock database (JSON file) used by JSON-Server
 app           <--- Main Application
 client        <--- React Application

Usage

  1. From, root directory, run:
  npm install
  1. Start json-server. This command includes a 2 second delay to mimic real world latency:
  cd mockDb
  json-server -H 0.0.0.0 --watch db.json -p 3001 -d 2000
  1. In a separate terminal window, navigate to root directory, and run this command to start both Node Express and React client concurrently
  npm run dev
  1. Navigate to localhost:8000 in your browser

Current Release

Currently only built to run on a development server. Configuration and build steps are needed for creation of a production instance.

Things that are incomplete and could be made better:

Code environment/process:

User experience/performance

  • Let user easily cipy URL (use SimpleCopy, or ClipboardJS)
  • Validation: check that user is entering a valid URL
  • Also test against internationalized resource identifiers (IRI) and internationalized domain names (IDN)
  • Short URLs not found on the system are handled poorly
  • Install polyfill for fetch to work with IE users
  • Explore ways to reduce React bundle size (e.g. tree shaking)
  • Animated loading indicators
  • Add cookie functionality (user's most recent short and long URLs)

License

Distributed under the ISC License. See LICENSE for more information.

shortener's People

Contributors

amardesi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.