-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.d.ts
202 lines (191 loc) · 5.33 KB
/
index.d.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
declare module 'spiderable-middleware' {
import type { IncomingMessage, ServerResponse, RequestOptions } from 'http';
import type { URL } from 'url';
/**
* Configuration options for Spiderable.
*/
export interface SpiderableOptions {
/**
* The URL of the rendering service.
* Defaults to the environment variable `SPIDERABLE_SERVICE_URL` or `PRERENDER_SERVICE_URL` if not provided.
*/
serviceURL?: string;
/**
* The root URL of your application.
* Defaults to the environment variable `ROOT_URL` if not provided.
*/
rootURL?: string;
/**
* Authentication credentials in the form "username:password".
*/
auth?: string;
/**
* When true, duplicate slashes in URLs will be sanitized.
*/
sanitizeUrls?: boolean;
/**
* An array of bot user-agent patterns.
*/
botsUA?: string[];
/**
* An array of header names to ignore when proxying responses.
*/
ignoredHeaders?: string[];
/**
* An array of URL paths to ignore.
*/
ignore?: string[];
/**
* An array of rules (strings or RegExp) for URLs that should be rendered exclusively.
*/
only?: (string | RegExp)[];
/**
* A RegExp to match URLs that should be rendered exclusively.
*/
onlyRE?: RegExp;
/**
* Request timeout in milliseconds.
*/
timeout?: number;
/**
* Additional request options (merged into the HTTP request payload).
*/
requestOptions?: RequestOptions;
/**
* When true, debug logging is enabled.
*/
debug?: boolean;
/**
* A regular expression to match static file extensions.
* (Not documented in the JS doc but used internally.)
*/
staticExt?: RegExp;
}
export type NextFunction = (err?: unknown) => void;
/**
* Spiderable middleware class for rendering pages for bots/crawlers.
*
* @example
* import Spiderable from 'spiderable-middleware';
* const spiderable = new Spiderable({
* rootURL: 'http://example.com',
* auth: 'test:test'
* });
*
* WebApp.connectHandlers.use(spiderable.handler);
*/
export default class Spiderable {
constructor(options?: SpiderableOptions);
/**
* Package name (set from package details).
*/
NAME: string;
/**
* The user agent used when sending requests to the rendering service.
*/
userAgent: string;
/**
* Authentication credentials.
*/
auth: string;
/**
* When true, enables debug logging.
*/
debug: boolean;
/**
* An array of "only" rules (strings or RegExp) or false if not defined.
*/
only: (string | RegExp)[] | false;
/**
* A RegExp built from the "only" rules or false if not defined.
*/
onlyRE: RegExp | false;
/**
* An array of bot user-agent patterns.
*/
botsUA: string[];
/**
* The root URL of the application.
*/
rootURL: string;
/**
* Request timeout (in milliseconds).
*/
timeout: number;
/**
* A RegExp to match static file extensions.
*/
staticExt: RegExp;
/**
* The rendering service URL.
*/
serviceURL: string;
/**
* When true, URLs are sanitized (removing duplicate slashes).
*/
sanitizeUrls: boolean;
/**
* An array of header names to ignore.
*/
ignoredHeaders: string[];
/**
* Additional options to be merged into the HTTP request payload.
*/
requestOptions: RequestOptions;
/**
* A RegExp built from the `ignoredHeaders` array.
*/
headersRE: RegExp;
/**
* A RegExp built from the `botsUA` array.
*/
botsRE: RegExp;
/**
* A RegExp built from the `ignore` option or false if not defined.
*/
ignoreRE: RegExp | false;
/**
* Constructs the complete service URL used to request a rendered page.
*
* @param urlObj - A URL object representing the original request.
* @param bua - Optional bot user-agent string (from the request headers).
* @returns A complete URL string to the rendering service.
*/
getServiceURL(urlObj: URL, bua?: string): string;
/**
* Processes the incoming request URL.
*
* @param req - The original HTTP request.
* @returns A URL object if the request qualifies for rendering, or false otherwise.
*/
getRequestURL(req: IncomingMessage): URL | false;
/**
* Express/connect–style middleware function.
*
* Processes the request and proxies a rendered response if applicable.
*
* @param req - The incoming HTTP request.
* @param res - The HTTP response.
* @param next - A function to call the next middleware.
* @returns true if the middleware handled the request, false otherwise.
*/
middleware(
req: IncomingMessage,
res: ServerResponse,
next: NextFunction
): boolean;
/**
* Alias for `middleware`. Can be used when mounting the middleware.
*/
handler: (req: IncomingMessage, res: ServerResponse, next: NextFunction) => boolean;
/**
* Alias for `middleware`.
*/
handle: (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
}
}
declare module 'meteor/ostrio:spiderable-middleware' {
export * from 'spiderable-middleware';
import Spiderable from 'spiderable-middleware';
export default Spiderable;
}