Simple URL shortener built using Typescript with Fastify and SQLite.
- Clone the repository
git clone https://github.com/madeindra/url-shortener.git
- Install dependencies
npm install
- Build the project
npm run build
- Export environment variables:
export PORT=3000
export HOST=localhost
export DB_PATH=database.db
export DB_TABLENAME=urls
- Start the server
npm start
- Build the image
docker build \
--build-arg PORT=3000 \
--build-arg HOST=0.0.0.0 \
--build-arg DB_PATH=database.db \
--build-arg DB_TABLENAME=urls \
--no-cache \
. -t yourusername/url-shortener:latest
- Run the container
docker run -d -p 3000:3000 yourusername/url-shortener:latest
-
Open your browser and visit
http://localhost:3000
-
Input your URL and custom slug (optional) to the form
-
Click
Shorten
button -
Copy the shortened URL
POST /shorten
{
"originalUrl": "https://www.google.com",
"customSlug": "google"
}
GET /:slug
- Add homepage with form to shorten URL
- Add docker support
- Add testings