web-check/api/quality.js

20 lines
669 B
JavaScript
Raw Normal View History

const axios = require('axios');
const middleware = require('./_common/middleware');
2023-06-18 22:01:13 +02:00
const handler = async (url, event, context) => {
const apiKey = process.env.GOOGLE_CLOUD_API_KEY;
2023-06-18 22:01:13 +02:00
2023-07-23 01:05:04 +02:00
if (!apiKey) {
throw new Error('API key (GOOGLE_CLOUD_API_KEY) not set');
2023-07-23 01:05:04 +02:00
}
2023-06-18 22:01:13 +02:00
const endpoint = `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=${encodeURIComponent(url)}&category=PERFORMANCE&category=ACCESSIBILITY&category=BEST_PRACTICES&category=SEO&category=PWA&strategy=mobile&key=${apiKey}`;
const response = await axios.get(endpoint);
return response.data;
2023-06-18 22:01:13 +02:00
};
module.exports = middleware(handler);
module.exports.handler = middleware(handler);