web-check/server/lambda/ssl-check.js
2023-06-20 23:01:45 +01:00

31 lines
637 B
JavaScript

const https = require('https');
exports.handler = async function (event, context) {
const { url } = event.queryStringParameters;
if (!url) {
return {
statusCode: 400,
body: 'url query parameter is required',
};
}
return new Promise((resolve, reject) => {
const req = https.request(url, res => {
resolve({
statusCode: 200,
body: JSON.stringify(res.socket.getPeerCertificate()),
});
});
req.on('error', (error) => {
resolve({
statusCode: 500,
body: `Error fetching site certificate: ${error.message}`,
});
});
req.end();
});
};