|
1 | 1 | declare namespace Deno { |
2 | 2 | interface Server { |
3 | | - [Symbol.asyncIterator](): AsyncGenerator<Conn>; |
4 | 3 | close(): void; |
5 | 4 | } |
6 | 5 |
|
7 | | - interface Conn extends Closer { |
8 | | - localAddr: Addr; |
9 | | - remoteAddr: Addr; |
10 | | - } |
11 | | - |
12 | | - interface NetAddr { |
13 | | - port: number; |
14 | | - } |
15 | | - |
16 | | - interface Listener extends Closer { |
17 | | - accept(): Promise<Conn>; |
18 | | - addr: Addr; |
19 | | - } |
20 | | - |
21 | 6 | interface Closer { |
22 | 7 | close(): void; |
23 | 8 | } |
24 | 9 |
|
25 | | - interface HttpConn extends Conn { |
26 | | - nextRequest(): Promise<RequestEvent>; |
27 | | - [Symbol.asyncIterator](): AsyncGenerator<RequestEvent>; |
28 | | - } |
29 | | - |
30 | | - interface RequestEvent { |
31 | | - request: Request; |
32 | | - respondWith(response: Response): Promise<void>; |
33 | | - } |
34 | | - |
35 | | - type ListenOptions = { port: number; hostname: string; transport: 'tcp' }; |
| 10 | + type ServeOptions = { |
| 11 | + port?: number; |
| 12 | + hostname?: string; |
| 13 | + onError?: (error: unknown) => Response | Promise<Response>; |
| 14 | + }; |
36 | 15 |
|
37 | | - type ListenTlsOptions = ListenOptions & { |
| 16 | + type ServeTlsOptions = ServeOptions & { |
38 | 17 | key: string; |
39 | 18 | cert: string; |
40 | | - alpnProtocols?: string[]; |
41 | 19 | }; |
42 | 20 |
|
43 | | - interface Addr {} |
44 | | -} |
45 | | - |
46 | | -interface Http { |
47 | | - new (message: string): Error; |
| 21 | + type ServeHandler = (request: Request) => Response | Promise<Response>; |
48 | 22 | } |
49 | 23 |
|
50 | 24 | const Deno: { |
51 | | - // https://deno.land/api@v1.33.4?s=Deno.listenTls |
52 | | - listenTls(options: Deno.ListenTlsOptions): Deno.Listener; |
53 | | - listen(options: Deno.ListenOptions): Deno.Listener; |
54 | | - serveHttp(connection: Deno.Conn): Deno.HttpConn; |
55 | 25 | env: { |
56 | 26 | get(name: string): string | undefined; |
57 | 27 | }; |
58 | 28 | readFileSync(path: string | URL): Uint8Array; // https://deno.land/api@v1.33.1?s=Deno.readFileSync |
59 | 29 | readTextFileSync(path: string): string; |
60 | 30 |
|
| 31 | + // https://deno.land/api@v1.35.0?s=Deno.serve |
| 32 | + serve( |
| 33 | + options: Deno.ServeOptions | Deno.ServeTlsOptions, |
| 34 | + handler: Deno.ServeHandler |
| 35 | + ): Deno.Server; |
| 36 | + |
61 | 37 | errors: { |
62 | 38 | BadResource; |
63 | 39 | InvalidData; |
|
0 commit comments