댓글 목록

[Nodejs] Deno HTTP 웹 서버 예 (Like Express)

페이지 정보

작성자 운영자 작성일 20-05-16 20:44 조회 905 댓글 0

Deno HTTP Web Server example (Like Express) 


https://crunchskills.com/deno-http-web-server-example-like-express/ 


Deno로 이사하는 많은 사람들은 Deno의 Express 웹 서버를 단순히 부트 스트랩 할 수 없다는 사실에 놀랐습니다. 

그러나 Deno는 비슷하고 훨씬 개선 된 웹 서버를 제공하며 똑같이 견딜 수 있습니다. 이 때문에 우리는 ? tasty를 소개했습니다! -Deno를 사용하여 간단한 API 및 웹 사이트를 제공하는 간단한 라우팅 프레임 워크.


예제 코드 :


import { serve, Server } from "https://deno.land/std@v0.42.0/http/server.ts";
import { tasty } from 'https://raw.githubusercontent.com/jquave/tasty/master/tasty.ts';

const s: Server = serve({ port: 8000 });

let router = new tasty.Router(s);

// Serve a static endpoint
router.on('/', (req) => {
    req.respond({ body: `Hello World!` })
});

// Serve a dynamic permalink
router.on('/:name', (req, query) => {
    req.respond({ body: `Hello ${query.get("name")}` })
});

이제 다음을 사용하여 간단한 웹 서버를 실행하십시오.


deno run --allow-net web.ts

http://localhost:8000/YourName에 추가 동적 경로가 있는 http://localhost:8000에서 hello world로 시작 및 실행하십시오.


공식 Github repository for tasty에서 자세히 알아보기



댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.