-
Notifications
You must be signed in to change notification settings - Fork 5
/
defaults.ts
106 lines (93 loc) · 2.58 KB
/
defaults.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
export interface ServePlaceholderOptions {
/**
* Sets `statusCode` for all handled responses. Set to `false` to disable overriding statusCode.
*
* @default 404
*/
statusCode?: number;
/**
* Skip middleware when no handler is defined for the current request.
* Please note that if this option is set to `true`, then `default` handler will be disabled
* @default false
*/
skipUnknown?: boolean;
/**
* Set headers to prevent accidentally caching 404 resources.
*
* @default true
*/
cacheHeaders?: boolean;
/**
* Sets an `X-Placeholder` header with value of handler name.
*
* @default true
*/
placeholderHeader?: boolean;
/**
* A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`.
* You can disable any of the handlers by setting the value to `null`
* If the value of a handler is set to `false`, the middleware will be ignored for that extension.
*/
handlers?: Record<string, string | false>;
/**
* A mapping from handler to placeholder. Values can be `String` or `Buffer`. You can disable any of the placeholders by setting the value to `false`.
*/
placeholders?: Record<string, string | undefined>;
/**
* A mapping from handler to the mime type. Mime type will be set as `Content-Type` header. You can disable sending any of the mimes by setting the value to `false`.
*/
mimes?: Record<string, string | undefined>;
}
export const DefaultOptions: ServePlaceholderOptions = {
statusCode: 404,
skipUnknown: false,
cacheHeaders: true,
placeholderHeader: true,
handlers: {
// css
".css": "css",
// html
".html": "html",
".htm": "html",
// image
".png": "image",
".jpg": "image",
".jpeg": "image",
".gif": "image",
".svg": "image",
".webp": "image",
".bmp": "image",
".ico": "image",
// js
".js": "js",
// json
".json": "json",
// map
".map": "map",
// plain
".txt": "plain",
".text": "plain",
".md": "plain",
},
placeholders: {
css: "/* style not found */",
default: undefined,
html: "<!-- page not found -->",
image:
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
js: "/* script not found */",
json: "{}",
map: '{"version": "3", "sources": [], "mappings": "" }',
plain: "",
},
mimes: {
css: "text/css",
default: undefined,
html: "text/html",
js: "application/javascript",
json: "application/json",
image: "image/gif",
map: "application/json",
plain: "text/plain",
},
};