-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add basic deno serve section (#442)
Co-authored-by: Bartek Iwańczuk <[email protected]>
- Loading branch information
1 parent
e201e4d
commit 4be6406
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
}, | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters