UNPKG

3.1 kBTypeScriptView Raw
1// Type definitions for gulp-connect 5.0
2// Project: https://github.com/avevlad/gulp-connect#readme
3// Definitions by: Andre Wiggins <https://github.com/andrewiggins>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.3
6
7import * as http from "http";
8import * as https from "https";
9import * as connectModule from "connect";
10
11export interface LiveReloadOptions {
12 /** Port to run live reload server on. Defauls to 35729. */
13 port: number;
14
15 /** Hostname to bind live reload server to */
16 hostname?: string | undefined;
17}
18
19/** a list of [string, HandlerFunction] where the string is the path (i.e. route) that the handler function should be invoked for */
20export type ConnectRouteHandler = [ string, connectModule.HandleFunction ];
21
22/**
23 * Factory function that returns a list of middleware handlers to pass to a connect server's use function.
24 * The list contain normal Connect middleware handler functions or ConnectRoutHandlers
25 */
26export type MiddlewareFactory = (connect: typeof connectModule, options: ConnectAppOptions) => Array<connectModule.HandleFunction | ConnectRouteHandler>;
27
28export interface ConnectAppOptions {
29 /** The name of this server. Used in logs. Defaults to "Server". */
30 name?: string | undefined;
31
32 /** The root path. Defaults to directory with gulpfile */
33 root?: string | string[] | undefined;
34
35 /** The connect webserver port. Defaults to 8080 */
36 port?: number | undefined;
37
38 /** Host to bind server to. Defaults to localhost. */
39 host?: string | undefined;
40
41 /** Don't log any messages. Defaults to false. */
42 silent?: boolean | undefined;
43
44 /**
45 * Options to pass to http.createServer (or false to disable https).
46 * Defaults to false. When https is just set to true, then internally
47 * some defaults will be used.
48 */
49 https?: boolean | https.ServerOptions | undefined;
50
51 /** Enable/disable livereload or set live reload options. Defaults to false. */
52 livereload?: boolean | LiveReloadOptions | undefined;
53
54 /** A function to run custom initialization on the underlying http or https server */
55 serverInit?(server: http.Server | https.Server): void;
56
57 /** File to serve if url results in a 404. Defaults to undefined */
58 fallback?: string | undefined;
59
60 /** Middleware factory function which should return a list of connect handler functions . Defaults to () => []; */
61 middleware?: MiddlewareFactory | undefined;
62
63 /** Whether or not to log debug messages. Defaults to false. */
64 debug?: boolean | undefined;
65
66 /** Value to pass into the serve-static's index option. See serve-static documentation for details. Defaults to true. */
67 index?: boolean | string | string[] | undefined;
68}
69
70/** Create a gulp-connect server with the given options */
71export function server(options?: ConnectAppOptions, startedCallback?: () => unknown): ConnectAppOptions;
72
73/** Reload all gulp-connect servers that have livereload enabled */
74export function reload(): any;
75
76/** Close all gulp-connect servers */
77export function serverClose(): void;