Fixed the categories param for the page speed API endpoint.

This commit is contained in:
M M committed 2024-07-24 12:33:41 -07:00
1 parent 2f5c51ebed
commit 825ab73d82
2 files changed
+20 -5

No files matched your search

+11 -4
View File
@@ -54,12 +54,19 @@ const createPageSpeedCheck = async (req, res, next) => {
// Run the PageSpeed check
const pageSpeedResults = await pageSpeedService.runPageSpeedCheck(url);
// Extract categories scores
const categories = pageSpeedResults.lighthouseResult?.categories;
if (!categories) {
throw new Error('Categories not found in PageSpeed results');
}
const newPageSpeedCheck = await pageSpeedService.createPageSpeedCheck({
monitorId,
accessibility: pageSpeedResults.lighthouseResult.categories.accessibility.score * 100,
bestPractices: pageSpeedResults.lighthouseResult.categories.best-practices.score * 100,
seo: pageSpeedResults.lighthouseResult.categories.seo.score * 100,
performance: pageSpeedResults.lighthouseResult.categories.performance.score * 100,
accessibility: (categories.accessibility?.score || 0) * 100,
bestPractices: (categories["best-practices"]?.score || 0) * 100,
seo: (categories.seo?.score || 0) * 100,
performance: (categories.performance?.score || 0) * 100,
});
return res.status(201).json({