Coder Social home page Coder Social logo

www-r / javascript__movie-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from parkyoungwoong/vanillajs-movie-app

0.0 0.0 0.0 758 KB

TS(JS) 영화 검색 사이트 예제 for FastCampus

Home Page: https://vanilla-movie-app.vercel.app/#/

TypeScript 68.62% CSS 28.15% HTML 3.24%

javascript__movie-app's Introduction

Movie App (TypeScript ver.)

OMDb API를 활용해 VanillaJS 영화 검색 애플리케이션을 만들어봅니다.
이 프로젝트는 JS 버전TS 버전으로 나누어져 있습니다.
기본 버전은 TS입니다.

DEMO

Screenshot

❗공지사항❗

2023년 4월 27일

Vercel Serverless Functions가 정상적으로 동작하기 위해 package.json 파일의 type 옵션을 요구하게 되었습니다.
package.json 파일에 다음과 같이 "type": "module" 옵션을 추가하세요.

{
  // ...
  "description": "",
  "type": "module",
  "scripts": {
  // ...
}

2023년 4월 23일

영화 검색 후 'View More..' 버튼이 보일 때, 다른 영화를 새롭게 검색해서 결과를 출력할 수 없는 경우에 'View More..' 버튼이 사라지지 않는 버그가 있습니다.
이는 pageMax 상태를 초기화하지 않아서 발생하는 문제이기 때문에, 다음과 같이 src/store/movie.ts 파일의 searchMovies 함수 내용에서 해당 초기화 코드를 추가해야 합니다!

if (Response === 'True') { // 77번째 줄
  store.state.movies = [
    ...store.state.movies,
    ...Search
  ]
  store.state.pageMax = Math.ceil(Number(totalResults) / 10)
} else {
  store.state.message = Error
  store.state.pageMax = 1 // 85번째 줄, 버그 수정을 위해 새롭게 추가된 코드!
}

프로젝트 시작하기

$ npm i
$ npm run vercel

Reset.css

브라우저의 기본 스타일을 초기화합니다.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/reset.min.css" />

Google Fonts

Oswald, Roboto 폰트를 사용합니다.

<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@500&family=Roboto:wght@400;700&display=swap" rel="stylesheet" />

Headline.js HTML

<h1>
  <span>OMDb API</span><br />
  THE OPEN<br />
  MOVIES DATABASE
</h1>
<p>
  The OMDb API is a RESTful web service to obtain movie information,
  all content and images on the site are contributed and maintained by our users.<br />
  If you find this service useful, please consider making a one-time donation or become a patron.
</p>

Vercel Hosting

node-fetch 패키지는 꼭 2버전으로 설치해야 합니다!

$ npm i -D vercel dotenv
$ npm i node-fetch@2

/vercel.json

{
  "devCommand": "npm run dev",
  "buildCommand": "npm run build"
}

/package.json

{
  "scripts": {
    "vercel": "vercel dev"
  }
}

Vercel 개발 서버 실행

Vercel 구성 이후에는 npm run dev가 아닌 npm run vercel로 개발 서버를 실행해야 합니다!

$ npm run vercel

Vercel Serverless Functions

프로젝트 루트 경로에 /api 폴더를 생성하고,
API Key 를 노출하지 않도록 서버리스 함수를 작성합니다.

/api/movie.ts

import { VercelRequest, VercelResponse } from '@vercel/node'
import fetch from 'node-fetch'

const { APIKEY } = process.env

export default async function handler(request: VercelRequest, response: VercelResponse) {
  const { title, page, id } = JSON.parse(request.body as string)
  const url = id
    ? `https://www.omdbapi.com/?apikey=${APIKEY}&i=${id}&plot=full`
    : `https://www.omdbapi.com/?apikey=${APIKEY}&s=${title}&page=${page}`
  const res = await fetch(url)
  const json = await res.json()
  response
    .status(200)
    .json(json)
}

환경변수

로컬의 개발용 서버에서 사용할 환경변수를 .env 파일에 지정합니다.

/.env

APIKEY=<MY_OMDb_API_KEY>

제품 서버(Vercel 서비스)에서 사용할 환경변수를 지정합니다.
Vercel 서비스의 프로젝트 'Settings / Environment Variables' 옵션에서 다음과 같이 환경변수를 지정합니다.

Screenshot

TypeScript

타입스크립트 코어 패키지와 node-fetch의 타이핑 패키지를 설치합니다.

$ npm i -D typescript @types/node-fetch@2

/tsconfig.json

{
  "compilerOptions": {
    "target": "ES2015",
    "module": "ESNext",
    "lib": ["ESNext", "DOM"],
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "api/**/*.ts"
  ]
}

JS 프로젝트가 없는 경우

타입스크립트를 시작할 기존의 JS 프로젝트를 가지고 있지 않다면, 다음과 같이 진행하세요!
진행이 끝나면, 루트 경로에 .env 파일을 생성하고 APIKEY 환경변수를 지정해야 합니다!

# 원하는 터미널 경로에서 완성된 프로젝트를 클론합니다.
$ git clone https://github.com/ParkYoungWoong/vanillajs-movie-app.git

# 클론한 프로젝트 폴더로 이동합니다.
$ cd vanillajs-movie-app

# 브랜치를 변경합니다.
$ git checkout typescript_starter

# Git 버전 관리 내역을 초기화합니다.
## macOS
$ rm -rf .git
## Windows
$ rmdir /s /q .git

# NPM 패키지를 설치합니다.
$ npm i

javascript__movie-app's People

Contributors

parkyoungwoong 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.