1 | // Inlined to avoid extra dependency
|
2 | // MIT Licensed https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/LICENSE
|
3 |
|
4 | // Type definitions for connect v3.4.0
|
5 | // Project: https://github.com/senchalabs/connect
|
6 | // Definitions by: Maxime LUCE <https://github.com/SomaticIT>
|
7 | // Evan Hahn <https://github.com/EvanHahn>
|
8 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
9 |
|
10 | /// <reference types="node" />
|
11 | import * as http from 'http'
|
12 |
|
13 | export namespace Connect {
|
14 | export type ServerHandle = HandleFunction | http.Server
|
15 |
|
16 | export class IncomingMessage extends http.IncomingMessage {
|
17 | originalUrl?: http.IncomingMessage['url']
|
18 | }
|
19 |
|
20 | export type NextFunction = (err?: any) => void
|
21 |
|
22 | export type SimpleHandleFunction = (
|
23 | req: IncomingMessage,
|
24 | res: http.ServerResponse
|
25 | ) => void
|
26 | export type NextHandleFunction = (
|
27 | req: IncomingMessage,
|
28 | res: http.ServerResponse,
|
29 | next: NextFunction
|
30 | ) => void
|
31 | export type ErrorHandleFunction = (
|
32 | err: any,
|
33 | req: IncomingMessage,
|
34 | res: http.ServerResponse,
|
35 | next: NextFunction
|
36 | ) => void
|
37 | export type HandleFunction =
|
38 | | SimpleHandleFunction
|
39 | | NextHandleFunction
|
40 | | ErrorHandleFunction
|
41 |
|
42 | export interface ServerStackItem {
|
43 | route: string
|
44 | handle: ServerHandle
|
45 | }
|
46 |
|
47 | export interface Server extends NodeJS.EventEmitter {
|
48 | (req: http.IncomingMessage, res: http.ServerResponse, next?: Function): void
|
49 |
|
50 | route: string
|
51 | stack: ServerStackItem[]
|
52 |
|
53 | /**
|
54 | * Utilize the given middleware `handle` to the given `route`,
|
55 | * defaulting to _/_. This "route" is the mount-point for the
|
56 | * middleware, when given a value other than _/_ the middleware
|
57 | * is only effective when that segment is present in the request's
|
58 | * pathname.
|
59 | *
|
60 | * For example if we were to mount a function at _/admin_, it would
|
61 | * be invoked on _/admin_, and _/admin/settings_, however it would
|
62 | * not be invoked for _/_, or _/posts_.
|
63 | */
|
64 | use(fn: NextHandleFunction): Server
|
65 | use(fn: HandleFunction): Server
|
66 | use(route: string, fn: NextHandleFunction): Server
|
67 | use(route: string, fn: HandleFunction): Server
|
68 |
|
69 | /**
|
70 | * Handle server requests, punting them down
|
71 | * the middleware stack.
|
72 | */
|
73 | handle(
|
74 | req: http.IncomingMessage,
|
75 | res: http.ServerResponse,
|
76 | next: Function
|
77 | ): void
|
78 |
|
79 | /**
|
80 | * Listen for connections.
|
81 | *
|
82 | * This method takes the same arguments
|
83 | * as node's `http.Server#listen()`.
|
84 | *
|
85 | * HTTP and HTTPS:
|
86 | *
|
87 | * If you run your application both as HTTP
|
88 | * and HTTPS you may wrap them individually,
|
89 | * since your Connect "server" is really just
|
90 | * a JavaScript `Function`.
|
91 | *
|
92 | * var connect = require('connect')
|
93 | * , http = require('http')
|
94 | * , https = require('https');
|
95 | *
|
96 | * var app = connect();
|
97 | *
|
98 | * http.createServer(app).listen(80);
|
99 | * https.createServer(options, app).listen(443);
|
100 | */
|
101 | listen(
|
102 | port: number,
|
103 | hostname?: string,
|
104 | backlog?: number,
|
105 | callback?: Function
|
106 | ): http.Server
|
107 | listen(port: number, hostname?: string, callback?: Function): http.Server
|
108 | listen(path: string, callback?: Function): http.Server
|
109 | listen(handle: any, listeningListener?: Function): http.Server
|
110 | }
|
111 | }
|