Skip to content

Commit

Permalink
fix: add basic deno serve section (#442)
Browse files Browse the repository at this point in the history
Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
mmastrac and bartlomieju authored Apr 24, 2024
1 parent e201e4d commit 4be6406
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/manual/tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
32 changes: 32 additions & 0 deletions runtime/manual/tools/serve.md
Original file line number Diff line number Diff line change
@@ -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!");
},
};
```
5 changes: 5 additions & 0 deletions sidebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4be6406

Please sign in to comment.