2024-05-06 22:51:32 +02:00
|
|
|
import axios from 'axios';
|
|
|
|
import middleware from './_common/middleware.js';
|
2023-08-22 22:40:22 +02:00
|
|
|
|
|
|
|
const MOZILLA_TLS_OBSERVATORY_API = 'https://tls-observatory.services.mozilla.com/api/v1';
|
|
|
|
|
2024-05-06 22:51:32 +02:00
|
|
|
const tlsHandler = async (url) => {
|
2023-08-22 22:40:22 +02:00
|
|
|
try {
|
|
|
|
const domain = new URL(url).hostname;
|
|
|
|
const scanResponse = await axios.post(`${MOZILLA_TLS_OBSERVATORY_API}/scan?target=${domain}`);
|
|
|
|
const scanId = scanResponse.data.scan_id;
|
|
|
|
|
|
|
|
if (typeof scanId !== 'number') {
|
|
|
|
return {
|
|
|
|
statusCode: 500,
|
2024-05-18 16:01:52 +02:00
|
|
|
body: { error: 'Failed to get scan_id from TLS Observatory' },
|
2023-08-22 22:40:22 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
const resultResponse = await axios.get(`${MOZILLA_TLS_OBSERVATORY_API}/results?id=${scanId}`);
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
2024-05-18 16:01:52 +02:00
|
|
|
body: resultResponse.data,
|
2023-08-22 22:40:22 +02:00
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
return { error: error.message };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-06 22:51:32 +02:00
|
|
|
export const handler = middleware(tlsHandler);
|
|
|
|
export default handler;
|