Skip to content

BrendoSPinheiro/shrtn-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

styled-components eslint airbnb-style MIT License PRs Welcome

Table of Contents

About

This project is a URL shortener developed for my course completion project. Its main objective is to have more control over the expiration of urls and validations of broken or nonexistent urls

Web

access the api source code here: WEB

Screenshots

Installing

First clone this repository:

$ git clone https://github.com/BrendoSPinheiro/shrtn-it.git

second go to the web folder

$ cd ./web

third install the dependencies:

$ yarn

Or:

$ npm install

Was installed and configured the eslint to keep the code clean and patterned.

Usage

To start up the app run:

$ yarn start

Or:

$ npm start

API

access the api source code here: API

Installing

First clone this repository:

$ git clone https://github.com/BrendoSPinheiro/shrtn-it.git

second go to the server folder

$ cd ./server

third install the dependencies:

$ yarn

Or:

$ npm install

Was installed and configured the eslint to keep the code clean and patterned.

Configuring

this application uses the PostgreSQL database.

PostgreSQL

Responsible for storing the data used by the application. For the fastest configuration it is recommended to use docker, you can create a postgresql container like this

$ docker run --name pg -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -p 5432:5432 -d postgres

You can find the application's knexfile.js file in the root folder. It already comes with test and development connection configured, so you will update it only when deploying

Migrations

Remember to run the PostgreSQL database migrations:

$ npx knex migrate:latest

Or:

$ yarn knex migrate:latest

See more information on Knex Migrations.

.env

in this file, you will configure the jwt key.

key description default
JWTSECRET A alphanumeric random string. Used to create signed tokens. -

Usage

To start up the app run:

$ yarn dev

Or:

$ npm run dev

Bearer Token

A few routes expect a Bearer Token in an Authorization header.

You can see these routes in the Routes section.

POST http://localhost:3001/urls Authorization: Bearer <token>

To achieve this token you just need authenticate through the /sessions route and it will return the token key with a valid Bearer Token.

Routes

route HTTP Method params description auth method
/urls GET Lists urls. Bearer
/urls/:id GET :id of the URL. Get url details. Bearer
/:slug GET :slug of the short url. Redirect short url.
/urls POST Body with new short url data. Create a new short url. Bearer
/urls/:id DELETE :id of the URL. Delete short url. Bearer
/users POST Body with new user data. Create a new user.
/session POST Body with user data. User authentication.

Routes with Bearer as auth method expect an Authorization header. See Bearer Token section for more information.

Requests

  • POST /urls

Request body:

// to shorten an unscheduled URL
{
  "title": "Google",
  "full_url": "https://google.com"
}

// to shorten a URL with scheduling by date
{
  "title": "Google",
  "full_url": "https://google.com",
  "scheduling_type": "date",
  "start_expires_date": "2021-01-20",
  "end_expires_date": "2021-01-22"
}

// to shorten a URL with scheduling by hour
{
  "title": "Google",
  "full_url": "https://google.com",
  "scheduling_type": "hour",
  "start_hour": 0,
  "end_hour": 2
}
  • POST /users
{
  "name": "Fulano",
  "email": "[email protected]",
  "password": "123456"
}
  • POST /session
{
  "email": "[email protected]",
  "password": "123456"
}

Contributors


Brendo Souza
Backend


Matheus Oliveira
Frontend


Emmanoell Pasquet
Author of the article