A simple URL shortener
- Node.js v10.x & NPM v6.2
- Mongo 2.2.3
- Clone this repo
- Run
npm install
to install dependencies - Run
npm run dep
to run dependencies like mongo and don't forget to enter root password after running command for mongo. - Open new terminal leaving previous one running
- Copy file
.env.example
to.env
and change env details if needed - Run command
npm run dev
- Then visit http://localhost:{port} to access app
A malicous user can enter same url to fill database with same url so to prevent this i have worked on both frontend and backend.
cors
Helps us protect from any cors related issuehelmet
Sends security related headerswinston
Simple logger transport layer for loggingnext
For server side rendering, static pages and routingreact
UI libraryyup
Object schema validator used for request/form validationaxios
Simple isomorphic http client
- We have rate limited our API so a malicous user can't request multiple times in certain window
- We have added some security related headers which will prevent us from common problems
- If a requested url for shortening is already available then we provide available short url to provide duplication as currently we don't have user account we won't have any problem.
- Once a user submits url and new short url is created it is stored in memory and whenever on next request if the requested url is found in cache then we return back previously created short url. This will prevent unnecessary request.
Currently our app can handle some amount of users but if in future if usage grows then we can do following things.
- Clustering application
- Load Balance and distrbute equally on nodes
- Instead of direct insert to database we can introduce some queuing technology (redis).
- We can maintain session to track url and avoid duplication of urls.