mirror of
https://github.com/Lissy93/web-check.git
synced 2024-11-26 02:03:24 +01:00
23 lines
717 B
JavaScript
23 lines
717 B
JavaScript
const axios = require('axios');
|
|
const middleware = require('./_common/middleware');
|
|
|
|
const handler = async (url, event, context) => {
|
|
const apiKey = process.env.GOOGLE_CLOUD_API_KEY;
|
|
|
|
if (!apiKey) {
|
|
throw new Error(
|
|
'Missing Google API. You need to set the `GOOGLE_CLOUD_API_KEY` environment variable'
|
|
);
|
|
}
|
|
|
|
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}`;
|
|
|
|
return (await axios.get(endpoint)).data;
|
|
};
|
|
|
|
module.exports = middleware(handler);
|
|
module.exports.handler = middleware(handler);
|