UNPKG

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