-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
186 lines (160 loc) · 4.36 KB
/
types.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
export type ConfigOptionalArray<T> = undefined | null | false | true | T | T[]
export enum CacheType {
/**
* Disable caching (useful for APIs)
*/
None = 'none',
/**
* Short time caching (useful for normal files likes index.html). Currently one minute
*/
Short = 'short',
/**
* Long term caching. Currently 7 days
*/
Long = 'long',
/**
* For files that never changed, usually with versions or hashes in their names. Currently one year. Adds `Cache-Control: immutable`
*/
Immutable = 'immutable',
}
export interface SPAServerHealthcheckConfig {
/**
* HTTP path on which to serve this healthcheck endpoint
*/
readonly path: string
/**
* Object containing data to serve on this endpoint or a function to generate said data
*/
readonly data?: any | (() => any)
}
export enum Preset {
/**
* Serve root without presets with only short time caching.
* **Do not use this**, it removes greatest benefit of SPA-PROD
*/
None = 'none',
/**
* Preset for Create React APP
* @see https://facebook.github.io/create-react-app/
*/
CRA = 'cra',
}
export interface SPAServerFolder {
/**
* Directory where to recursively look for files
*/
readonly root: string
/**
* HTTP path from which to server this folder
* @default /
*/
readonly path?: string
/**
* Caching policy for files in this folder.
* You will usually want to use either `short` or `immutable`.
* Each policy has it's own headers
* @default "short"
*/
readonly cache?: CacheType
}
export interface SPACSPConfig {
/**
* Additional CSP rules
* @example
* {
* 'script-src': ['https://example.com'],
* 'style-src': ['data:'],
* }
*/
readonly append?: Record<string, string[]>
/**
* CSP report uri
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-uri
*/
readonly reportUri?: string
/**
* Run CSP in report only mode. Requires `reportUri`
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
* @default false
*/
readonly reportOnly?: boolean
/**
* Enable `require-sri-for` directive
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-sri-for
* @default false
*/
readonly requireSri?: boolean
}
export interface SPAServerConfig {
/**
* Listen port
* Do not forget to update HEALTHCHECK in your Dockerfile if you change this from 8080
* @default 8080
*/
readonly port: number
/**
* Folders to serve
*/
readonly folders: SPAServerFolder[]
/**
* Index.html file path
*/
readonly index: string
/**
* Working directory for relative paths.
* This is set automatically by CLI to be folder of the config file
*/
readonly cwd?: string
/**
* Healthcheck endpoint configuration
*/
readonly healthcheck?: ConfigOptionalArray<SPAServerHealthcheckConfig>
/**
* Should logs be printed?
*/
readonly silent?: boolean
/**
* Whitelisted environment variables to be injected into index
*/
readonly envs?: string[]
/**
* Property to inject envs into
* @default "window.__env"
*/
readonly envsPropertyName?: string
/**
* Send 403 for source maps when false. This should be set to `false` in real PROD environment (but it is very useful in DEV envs)
* @default true
*/
readonly sourceMaps?: boolean
/**
* Inject prefetch links into index HTML for js and css assets
* @default true
*/
readonly prefetch?: boolean
/**
* Enable Subresource Integrity tag injection into index for styles and scripts
* @see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
* @default true
*/
readonly sri?: boolean
/**
* Enable Content Security Policy
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
* @default false
*/
readonly csp?: SPACSPConfig | boolean
/**
* Basic authentication username
*/
readonly username?: string
/**
* Basic authentication password
*/
readonly password?: string
/**
* Send `X-Powered-By` header (SPA-PROD, Express)
* @default true
*/
readonly poweredBy?: boolean
}