<commit_before>const TLSARecord = require('../index.js')
const https = require('https')

module.exports = (req, res) => {
  let body = ''
  res.setHeader('Access-Control-Allow-Origin', '*')
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
  res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept')
  res.setHeader('Content-Type', 'application/json')
  if (req.method === 'POST') {
    req.on('data', chunk => { body += chunk.toString() })
    req.on('end', () => {
        body = JSON.parse(body)
        console.log(body)
        https.get('https://' + body.domain, (resp) => {
            const tlsaRecord = new TLSARecord(resp.connection.getPeerCertificate().raw)
            const result = {  
                record: tlsaRecord.toString(
                    parseInt(body.usage),
                    parseInt(body.selector),
                    parseInt(body.matchingType),
                    body.domain,
                    parseInt(body.port),
                    body.protocol),
                status: 'ok'
            }
            console.log(result)
            res.end(JSON.stringify(result))
        }).on("error", err => {
            console.log(err)
            res.end('{"status":"error"}')
        })
    })<commit_msg>fix: use tls<commit_after>const TLSARecord = require('../index.js')
const tls = require('tls')

module.exports = (req, res) => {
  let body = ''
  res.setHeader('Access-Control-Allow-Origin', '*')
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
  res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept')
  res.setHeader('Content-Type', 'application/json')
  if (req.method === 'POST') {
    req.on('data', chunk => { body += chunk.toString() })
    req.on('end', () => {
        body = JSON.parse(body)
        tls.connect(parseInt(body.port), body.domain, function() { 
            const tlsaRecord = new TLSARecord(this.getPeerCertificate().raw)
            res.end(JSON.stringify({
                record: tlsaRecord.toString(
                    parseInt(body.usage),
                    parseInt(body.selector),
                    parseInt(body.matchingType),
                    body.domain,
                    parseInt(body.port),
                    body.protocol),
                status: 'ok'
            }))
        })
    })
{'fraction_non_alphanumeric': 0.16189290161892902, 'fraction_numerical': 0.0, 'mean_word_length': 2.0238393977415305, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2585223', 'n_tokens_mistral': 720, 'n_tokens_neox': 697, 'n_words': 114}