A basic URL shortener that takes a URL, consistently hashes it and stores it in a sharded database using hash-ring (Chooses a DB connection from a pool based on the hashed URL).
Returns JSON response
POST
: http://localhost:3000/?url=:url (url = url to shorten)GET
: http://localhost:3000/:urlId (urlId = shortened URL)
- docker >= 17.12.0+
- docker-compose
- node.js
- npm
-
Just go on official Node.js website and download the installer. Also, be sure to have
git
available in your PATH,npm
might need it (You can find git here). -
You can install nodejs and npm easily with apt install, just run the following commands.
$ sudo apt install nodejs $ sudo apt install npm
-
You can find more information about the installation on the official Node.js website and the official NPM website.
If the installation was successful, you should be able to run the following command.
$ node --version
v8.11.3
$ npm --version
6.1.0
If you need to update npm
, you can make it using npm
! Cool right? After running the following command, just open again the command line and be happy.
$ npm install npm -g
- Clone or download this repository
- Go inside the directory
- Run this command to build docker file
docker build -t pgshard .
- Run this command
docker-compose up -d
This Compose file contains the following environment variables:
POSTGRES_USER
the default value is postgresPOSTGRES_PASSWORD
the default value is changemePGADMIN_PORT
the default value is 5050PGADMIN_DEFAULT_EMAIL
the default value is pgadmin4@pgadmin.orgPGADMIN_DEFAULT_PASSWORD
the default value is admin
localhost:5432
- Username: postgres (as a default)
- Password: changeme (as a default)
- URL:
http://localhost:5050
- Username: pgadmin4@pgadmin.org (as a default)
- Password: admin (as a default)
- Name
shard1
- Host name/address
postgres1
- Port
5432
- Username as
POSTGRES_USER
, by default:postgres
- Password as
POSTGRES_PASSWORD
, by defaultchangeme
- Name
shard2
- Host name/address
postgres2
- Port
5432
- Username as
POSTGRES_USER
, by default:postgres
- Password as
POSTGRES_PASSWORD
, by defaultchangeme
- Name
shard3
- Host name/address
postgres3
- Port
5432
- Username as
POSTGRES_USER
, by default:postgres
- Password as
POSTGRES_PASSWORD
, by defaultchangeme
- Change local machine hostname in index.js
- Make sure the databases are running
- In the current directory
npm start