2 2 Node Chap 5 Starting Node Chap

  • Slides: 32
Download presentation

2 2. Node 시작하기 Chap 5. Starting Node Chap 6. Starting a Node Server

2 2. Node 시작하기 Chap 5. Starting Node Chap 6. Starting a Node Server Chap 7. Routing Node Applications

Node로 웹서버 만들어보기 14 (1) Node 만으로 웹서버 만들기 (express 사용 안함) (2) Express를

Node로 웹서버 만들어보기 14 (1) Node 만으로 웹서버 만들기 (express 사용 안함) (2) Express를 이용하여 웹서버 쉽게 만들기 http-server 프로젝트 폴더를 만들고 package. json과 index. html 파일을 만들자. Package. json: { } "name": "http-server", "version": "1. 0. 0", "description": "", "main": "server. js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "", "license": "ISC" Index. html: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title> First date</title> </head> <body> <h 1> Hello Universe! </h 1> </body> </html>

(2) Express를 이용하여 웹서버 쉽게 만들기 19 Express API document 참조 https: //expressjs. com/en/4

(2) Express를 이용하여 웹서버 쉽게 만들기 19 Express API document 참조 https: //expressjs. com/en/4 x/api. html

라우팅 23 현재의 홈페이지에 다음 기능들을 추가해보자. • • Basic Routes (We’ve already created

라우팅 23 현재의 홈페이지에 다음 기능들을 추가해보자. • • Basic Routes (We’ve already created the homepage) Site Section Routes (Admin section with sub routes) Route Middleware to log requests to the console Route with Parameters (http: //localhost: 1337/users/holly) Route Middleware for Parameters to validate specific parameters Login routes doing a GET and POST on /login Validate a parameter passed to a certain route • • 기본 루트 admin 섹션 라우팅 /admin route 미들웨어를 이용하여 서버의 콘솔에 request 로그 남기기 파라메터를 이용하는 라우팅 (http: //localhost: 1337/users/holly) route 미들웨어를 이용하여 파라메터의 유효성 검사 로그인 루트 제공 /login 루트에서 GET, POST 기능 어떤 루트에 전달된 파라메터의 유효성 검증

라우팅 기능 요약 32 Express의 router는 여러 가지 유연한 방식으로 라우트 를 정의할 수

라우팅 기능 요약 32 Express의 router는 여러 가지 유연한 방식으로 라우트 를 정의할 수 있음 � � � Use express. Router() multiple times to define groups of routes Apply the express. Router() to a section of our site using app. use() Use route middleware to process requests Use route middleware to validate parameters using. param() Use app. route() as a shortcut to the Router to define multiple requests on a route