This repository was archived by the owner on Sep 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +3
-11
lines changed Expand file tree Collapse file tree 1 file changed +3
-11
lines changed Original file line number Diff line number Diff line change 9
9
With just a few lines of code you can run your own HTTP web server with control
10
10
over the response status, request headers and more.
11
11
12
- ## Sample web server
12
+ ## Using the ` Deno.listen `
13
13
14
14
In this example, the user-agent of the client is returned to the client:
15
15
@@ -57,19 +57,11 @@ deno run --allow-net webserver.ts
57
57
58
58
Then navigate to ` http://localhost:8080/ ` in a browser.
59
59
60
- ### Using the ` std/http ` library
61
-
62
- > ℹ️ Since
63
- > [ the stabilization of _ native_ HTTP bindings in
64
- ` ^1.13.x ` ] ( https://deno.com/blog/v1.13#stabilize-native-http-server-api ) ,
65
- > std/http now supports a _ native_ HTTP server from ^0.107.0. The legacy server
66
- > module was removed in 0.117.0.
60
+ ### Using the ` Deno.serve `
67
61
68
62
** webserver.ts** :
69
63
70
64
``` ts
71
- import { serve } from " https://deno.land/std@$STD_VERSION/http/server.ts" ;
72
-
73
65
const port = 8080 ;
74
66
75
67
const handler = (request : Request ): Response => {
@@ -81,7 +73,7 @@ const handler = (request: Request): Response => {
81
73
};
82
74
83
75
console .log (` HTTP webserver running. Access it at: http://localhost:8080/ ` );
84
- await serve (handler , { port });
76
+ Deno . serve ({ port }, handler );
85
77
```
86
78
87
79
Then run this with:
You can’t perform that action at this time.
0 commit comments