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