This project is a URL shortening service built with Express.js and TypeScript. It provides functionalities to shorten URLs, decode shortened URLs, retrieve URL statistics, and redirect to original URLs.
- Node.js (v14 or later)
- npm (Node Package Manager)
- Docker (optional, for running the project in a Docker container)
git clone https://github.com/mikkybang/short-link.git
# Change to the project directory
cd short-link
Setup your env variables using the example defined [here](https://github.com/mikkybang/short-link/blob/main/env.example)
You can create a `.env` file or set your OS environment variables
# Install the dependencies
npm install
To run the project on your local machine, follow these steps:
- Transpile TypeScript to JavaScript:
npm run build
- Start the server:
npm start
Now, the server should be running at http://localhost:3003.
Alternatively, you can run the project inside a Docker container using the following steps:
- Build the Docker image:
docker build -t short-link .
- Run a Docker container from the image:
docker run --env-file .env -p 3003:3003 -d short-link
The application will be accessible at http://localhost:3003.
- Endpoint:
POST /encode
- Body:
{ "url": "http://example.com" }
- Response: The shortened URL details.
- Endpoint:
POST /decode
- Body:
{ "url": "https://shortlink.com/1bf410" }
- Response: The original URL.
- Endpoint:
GET /statistic/:url_path
- Response: Statistics for the specified URL path.
- Endpoint:
GET /:hash
- Response: Redirects to the original URL associated with the hash.
This project is licensed under the ISC License.