Greetings, traveler. This is a WIP project (Work in Progress Project) of a URL shortener made out to shorten and redirect a user towards an original previously typed-in page. It was primarily programmed to be a microservice component, and it all started from a technical challenge for a job interview.
Wanna see it? >> https://url-shortener1234567.herokuapp.com/encurtador
Want to see its documentation? There is a little story there.
https://documenter.getpostman.com/view/15716598/TzRVdRAp
- TypeScript (compiled to Javascript).
- NodeJS;
- Express + Jest;
- PostgreSQL through pg;
- Postman;
- Docker;
There are two ways you can run this server:
-
- npm run postinstall followed by npm start for production purposes.
-
- npm run dev for development and continuous debugging.
- Install and save these packages for development purposes:
- ts-node-dev for simultaneous alterations;
- config + @types/config;
- express + @types/express;
- jest + ts-jest + @types/jest;
- typescript + @types/node;
- ejs for user interface;
- body-parser to store data as JSON;
- pg (postgres module);
-
Set up an Express app for the server.
-
Create a test file that will at first fail the test, as there is no code written. After, a mock test in order to test importing of node_modules from the app to the test file will be done.
-
If passed, all possibilities that should be accounted for in a test will be written down so there is Test-Driven Development;
-
Create a static front-end file with forms.
-
Write HTTP request methods and create shortener function.
-
Deploy to Heroku.
-
Connect to a database in order to save Urls.
-
Use Postman to test methods and save collection to package.
-
Redirect user to longUrl page.
-
Write functions that suffice the tests passing.
-
Package using Dockerfile.
- User ask for the server to shorten a link. That does 2 things:
- It sends a POST request method consisted of the original URL (URL in test was http://wisereducacao.com) to the server, with a route named "http://localhost:8001/encurtador".
-
Then, the server creates the shortened URL called as a "newUrl" attribute in a JSON file with an index number and stored in the database.
-
Server returns the shortUrl to the user.
-
When the user makes use of the shortened URL, the user is by consequence issuing a GET request for the original URL as well, which is saved in the database. It can either redirect the user towards the original URL, or return a HTTP 404 response.