UNPKG

3.04 kBTypeScriptView Raw
1/**
2 * Interface describing options for serving static assets.
3 *
4 * @see [Serving static files in Express](https://expressjs.com/en/starter/static-files.html)
5 * @see [Model-View-Controller](https://docs.nestjs.com/techniques/mvc)
6 *
7 * @publicApi
8 */
9export interface ServeStaticOptions {
10 /**
11 * Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
12 * Note this check is done on the path itself without checking if the path actually exists on the disk.
13 * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny").
14 * The default value is 'ignore'.
15 * 'allow' No special treatment for dotfiles
16 * 'deny' Send a 403 for any request for a dotfile
17 * 'ignore' Pretend like the dotfile does not exist and call next()
18 */
19 dotfiles?: string;
20 /**
21 * Enable or disable etag generation, defaults to true.
22 */
23 etag?: boolean;
24 /**
25 * Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for.
26 * The first that exists will be served. Example: ['html', 'htm'].
27 * The default value is false.
28 */
29 extensions?: string[];
30 /**
31 * Let client errors fall-through as unhandled requests, otherwise forward a client error.
32 * The default value is false.
33 */
34 fallthrough?: boolean;
35 /**
36 * Enable or disable the immutable directive in the Cache-Control response header.
37 * If enabled, the maxAge option should also be specified to enable caching. The immutable directive will prevent supported clients from making conditional requests during the life of the maxAge option to check if the file has changed.
38 */
39 immutable?: boolean;
40 /**
41 * By default this module will send "index.html" files in response to a request on a directory.
42 * To disable this set false or to supply a new index pass a string or an array in preferred order.
43 */
44 index?: boolean | string | string[];
45 /**
46 * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.
47 */
48 lastModified?: boolean;
49 /**
50 * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.
51 */
52 maxAge?: number | string;
53 /**
54 * Redirect to trailing "/" when the pathname is a dir. Defaults to true.
55 */
56 redirect?: boolean;
57 /**
58 * Function to set custom headers on response. Alterations to the headers need to occur synchronously.
59 * The function is called as `fn(res, path, stat)`, where the arguments are:
60 * `res` - the response object
61 * `path` - the file path that is being sent
62 * `stat` - the stat object of the file that is being sent
63 */
64 setHeaders?: (res: any, path: string, stat: any) => any;
65 /**
66 * Creates a virtual path prefix
67 */
68 prefix?: string;
69}