Updates all API endpoints to use common middleware

This commit is contained in:
Alicia Sykes
2023-08-09 22:33:36 +01:00
parent 85af5f9327
commit d2a56eb526
21 changed files with 264 additions and 550 deletions

View File

@@ -1,14 +1,7 @@
const https = require('https');
const middleware = require('./_common/middleware');
exports.handler = async (event, context) => {
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return {
statusCode: 400,
body: JSON.stringify({ error: 'url query parameter is required' }),
};
}
const handler = async (url) => {
// First, get the size of the website's HTML
const getHtmlSize = (url) => new Promise((resolve, reject) => {
@@ -42,14 +35,10 @@ exports.handler = async (event, context) => {
});
carbonData.scanUrl = url;
return {
statusCode: 200,
body: JSON.stringify(carbonData),
};
return carbonData;
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: `Error: ${error.message}` }),
};
throw new Error(`Error: ${error.message}`);
}
};
exports.handler = middleware(handler);