Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add basic deno serve section #442

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading