Repository navigation
Expand file tree
/
Copy pathperformance.http.ts
More file actions
72 lines (65 loc) · 1.72 KB
/
Copy pathperformance.http.ts
File metadata and controls
72 lines (65 loc) · 1.72 KB
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
import {
APITags,
BrowserHTTPRoute,
BrowserInstance,
BrowserlessRoutes,
CDPLaunchOptions,
ChromiumCDP,
HTTPRoutes,
Logger,
Methods,
Request,
SystemQueryParameters,
assertNavigationAllowed,
contentTypes,
jsonResponse,
} from '@browserless.io/browserless';
import { ServerResponse } from 'http';
import main from './utils/performance/main.js';
export interface BodySchema {
budgets?: Array<object>;
config?: object;
url: string;
}
export interface QuerySchema extends SystemQueryParameters {
launch?: CDPLaunchOptions | string;
}
/**
* The response of the lighthouse stats. Response objects are
* determined by the type of budgets and config in the POST
* JSON body
*/
export type ResponseSchema = object;
export default class PerformancePost extends BrowserHTTPRoute {
name = BrowserlessRoutes.ChromiumPerformancePostRoute;
accepts = [contentTypes.json];
auth = true;
browser = ChromiumCDP;
concurrency = true;
contentTypes = [contentTypes.json];
description = `Run lighthouse performance audits with a supplied "url" in your JSON payload.`;
method = Methods.post;
path = [HTTPRoutes.chromiumPerformance, HTTPRoutes.performance];
tags = [APITags.browserAPI];
async handler(
req: Request,
res: ServerResponse,
_logger: Logger,
browser: BrowserInstance,
): Promise<void> {
const config = this.config();
const { url } = req.body as BodySchema;
assertNavigationAllowed(
url,
config.getBlockedURLPatterns(),
config.getBlockedNetworkRanges(),
);
const response = await main({
browser,
context: req.body as BodySchema,
logger: _logger,
timeout: config.getTimeout(),
});
return jsonResponse(res, 200, response);
}
}