Giter Club home page Giter Club logo

short_url's Introduction

short url 생성 기능 : 구조 만들기, 데이터베이스 설계 및 구축

short Url의 활용

어느 서비스에서나 쓰일 수 있는 url 주소 단축 기능은, 주로 주소 복사 및 공유할 때 쓰인다. 불필요하게 긴 주소는 공유할 때 번거롭기 때문이다. 이번 프로젝트에서는 단순 기능개발에 목적을 두기보다, 구조화와 개발 환경 구축에 초점을 맞추었다.

백엔드 작업

  1. 구조화: 코드 중복을 최소화하기 위해 서비스 클래스를 구조화 / ‘NestJS Exception Filter’
  2. DB 만들기 = entity, table 등
  3. 초기세팅 (nestJs, typescript, typeorm, ormconfig.js) : nest cli
  4. short url 생성 api 만들기

플로우

1) short url 생성

  • original url, user ip 를 서버에 전송 (POST)

  • 서버에서 short url 생성

    1. localhost:3000/ 뒤에 위치하는 shorturl (const fullShortUrl = baseUrl + shortUrl; )

    2. short url 고유하게 만드는 로직: (도메인 부분을 제외한) 뒷부분’ 절대 중복되지 않도록 (영문 대소문자, 가끔 하나의 숫자)

    3. user ip로 하루 short URL 변환 횟수 확인: 저장한 ip 주소 - 일 30회만 변환 가능하게 작업

  • DB에 데이터 저장: original url , short url, user IP (insert into)

  • short url 반환 (return)

2) short url로 접속

DB에서 원래 주소를 찾은 후 Redirect : 서버에서 - 뒷부분 조회 (select) : mapping 된 거를 redirect 시킴

  • url의 parameter(short url)로 DB에서 original url 검색(조회 = select)
  • original url로 Redirect

DB 설정

  • ormconfig.js 파일 생성
  • shorturl 칼럼에 unique 제약조건 추가

image

일반적으로 사용되는 https://www.shorturl.at/ , https://bitly.com/ 를 참고하여, 도메인 부분은 localhost:port로 default 값으로 하고, 뒷부분이 변경되도록

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

short_url's People

Contributors

developerpmyj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.