2023-07-22 16:18:28 +02:00
|
|
|
const axios = require('axios');
|
2023-08-09 23:33:36 +02:00
|
|
|
const middleware = require('./_common/middleware');
|
2023-06-18 22:01:13 +02:00
|
|
|
|
2023-08-09 23:33:36 +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) {
|
2023-08-09 23:33:36 +02:00
|
|
|
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}`;
|
2023-08-09 23:33:36 +02:00
|
|
|
|
|
|
|
const response = await axios.get(endpoint);
|
2023-07-22 16:18:28 +02:00
|
|
|
|
2023-08-09 23:33:36 +02:00
|
|
|
return response.data;
|
2023-06-18 22:01:13 +02:00
|
|
|
};
|
2023-08-09 23:33:36 +02:00
|
|
|
|
2023-09-03 13:27:04 +02:00
|
|
|
module.exports = middleware(handler);
|
|
|
|
module.exports.handler = middleware(handler);
|