From 4c394ecb9d8c691928cf8bc7e72ee3283d8e535c Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Wed, 24 Apr 2024 14:26:27 -0400 Subject: [PATCH 1/2] fix: add basic deno serve section --- .../getting_started/command_line_interface.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/runtime/manual/getting_started/command_line_interface.md b/runtime/manual/getting_started/command_line_interface.md index 58b1274a8..cb8f1c18f 100644 --- a/runtime/manual/getting_started/command_line_interface.md +++ b/runtime/manual/getting_started/command_line_interface.md @@ -232,6 +232,28 @@ More flags which affect the execution environment. --v8-flags= Set V8 command line options. For help: ... ``` +## Serving + +In addition to `deno run`, Deno offers a `deno serve` command-line option that +automatically configures servers based on the exports of your main module. + +Here's a basic example of how you can create a simple HTTP server using the +`serve` subcommand: + +```typescript +export default { + async fetch(request) { + // Your server logic goes here + return new Response("Hello world!"); + }, +}; +``` + +In this example, the fetch function is used to handle incoming HTTP requests. +You can customize the logic inside the fetch function to handle different types +of requests and serve content accordingly. This is just a starting point, and +you can build more complex server applications using Deno's powerful runtime. + ## Autocomplete You can get IDE-style autocompletions for Deno with [Fig](https://fig.io/) From 90cceb1092ab83803a151dba2312682efcd1648e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Apr 2024 20:35:04 +0200 Subject: [PATCH 2/2] update --- .../getting_started/command_line_interface.md | 22 ------------- runtime/manual/tools/index.md | 1 + runtime/manual/tools/serve.md | 32 +++++++++++++++++++ sidebars/runtime.js | 5 +++ 4 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 runtime/manual/tools/serve.md diff --git a/runtime/manual/getting_started/command_line_interface.md b/runtime/manual/getting_started/command_line_interface.md index cb8f1c18f..58b1274a8 100644 --- a/runtime/manual/getting_started/command_line_interface.md +++ b/runtime/manual/getting_started/command_line_interface.md @@ -232,28 +232,6 @@ More flags which affect the execution environment. --v8-flags= Set V8 command line options. For help: ... ``` -## Serving - -In addition to `deno run`, Deno offers a `deno serve` command-line option that -automatically configures servers based on the exports of your main module. - -Here's a basic example of how you can create a simple HTTP server using the -`serve` subcommand: - -```typescript -export default { - async fetch(request) { - // Your server logic goes here - return new Response("Hello world!"); - }, -}; -``` - -In this example, the fetch function is used to handle incoming HTTP requests. -You can customize the logic inside the fetch function to handle different types -of requests and serve content accordingly. This is just a starting point, and -you can build more complex server applications using Deno's powerful runtime. - ## Autocomplete You can get IDE-style autocompletions for Deno with [Fig](https://fig.io/) diff --git a/runtime/manual/tools/index.md b/runtime/manual/tools/index.md index 5a206d32e..14a9922f8 100644 --- a/runtime/manual/tools/index.md +++ b/runtime/manual/tools/index.md @@ -16,6 +16,7 @@ Deno features before they are finalized. - [formatter (`deno fmt`)](./formatter.md) - [linter (`deno lint`)](./linter.md) - [repl (`deno repl`)](./repl.md) +- [server (`deno serve`)](./serve.md) - [task runner (`deno task`)](./task_runner.md) - [test runner (`deno test`)](../basics/testing/index.md) - [vendoring dependencies (`deno vendor`)](./vendor.md) diff --git a/runtime/manual/tools/serve.md b/runtime/manual/tools/serve.md new file mode 100644 index 000000000..9b80518f3 --- /dev/null +++ b/runtime/manual/tools/serve.md @@ -0,0 +1,32 @@ +# `deno serve`, declarative way to write servers + +In addition to `deno run`, Deno offers a `deno serve` command-line option that +automatically configures servers based on the exports of your main module. + +Here's an example of how you can create a simple HTTP server using the `serve` +subcommand: + +```typescript +export default { + async fetch(request) { + return new Response("Hello world!"); + }, +}; +``` + +In this example, the `fetch` function is used to handle incoming HTTP requests. + +The logic inside the `fetch` function can be customized to handle different +types of requests and serve content accordingly: + +```typescript +export default { + async fetch(request) { + if (request.url.startsWith("/json")) { + return Response.json({ hello: "world" }); + } + + return new Response("Hello world!"); + }, +}; +``` diff --git a/sidebars/runtime.js b/sidebars/runtime.js index af3c6f07c..b5ab0fbd2 100644 --- a/sidebars/runtime.js +++ b/sidebars/runtime.js @@ -180,6 +180,11 @@ const sidebars = { label: "deno run", id: "manual/tools/run", }, + { + type: "doc", + label: "deno serve", + id: "manual/tools/serve", + }, { type: "doc", label: "deno task",