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,WACpB,KAAM,CACF,KAAM,QAAQ,IAAI,WAClB,KAAM,QAAQ,IAAI,cAI1B,SAAS,SAAS,GAEhB,IAAI,EAAc,CACd,KAAM,QAAQ,IAAI,MAAQ,8CAC1B,GAAI,QAAQ,IAAI,GAChB,QAAS,uBAAyB,QAAQ,IAAI,UAAY,OAAS,QAAQ,IAAI,UAAY,IAC3F,KAAM,GAEV,QAAQ,IAAI,kBAAmB,GAG/B,YAAY,SAAS,GAAa,CAAC,EAAO,KACtC,GAAI,EACA,OAAO,QAAQ,IAAI,GAEvB,QAAQ,IAAI,sBAAuB,EAAK,UAAW,EAAK,SAAS,GAEvE","file":"/npm/serverless-form@1.0.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/serverless-form@1.0.6/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\nvar http = require('http');\nvar fs = require('fs');\nvar formidable = require(\"formidable\");\nvar util = require('util');\nvar nodemailer = require('nodemailer');\n\n// setup the server\n// listen on port specified by the `PORT` env var\nvar server = http.createServer(function (req, res) {\n    if (req.method.toLowerCase() == 'get') {\n        displayForm(res);\n    } else if (req.method.toLowerCase() == 'post') {\n        //processAllFieldsOfTheForm(req, res);\n        processFormFieldsIndividual(req, res);\n    }\n});\nvar port = process.env.PORT || 8080;\nserver.listen(port);\nconsole.log(\"server listening on \", port);\n\n// serve HTML file\n// located according to the `FORM` env var\nfunction displayForm(res) {\n    fs.readFile(process.env.FORM || 'form.html', function (err, data) {\n        res.writeHead(200, {\n            'Content-Type': 'text/html',\n                'Content-Length': data.length\n        });\n        res.write(data);\n        res.end();\n    });\n}\n\n// get the POST data \n// and call the sendMail method\nfunction processAllFieldsOfTheForm(req, res) {\n    var form = new formidable.IncomingForm();\n\n    form.parse(req, function (err, fields, files) {\n        //Store the data from the fields in your data store.\n        //The data store could be a file or database or any other store based\n        //on your application.\n        res.writeHead(200, {\n            'content-type': 'text/plain'\n        });\n        res.write('received the data:\\n\\n');\n        res.end(util.inspect({\n            fields: fields,\n            files: files\n        }));\n    });\n}\n\nfunction processFormFieldsIndividual(req, res) {\n    //Store the data from the fields in your data store.\n    //The data store could be a file or database or any other store based\n    //on your application.\n    var fields = [];\n    var form = new formidable.IncomingForm();\n    form.on('field', function (field, value) {\n        console.log(field);\n        console.log(value);\n        fields[field] = value;\n    });\n\n    form.on('end', function () {\n        res.writeHead(200, {\n            'content-type': 'text/html'\n        });\n        sendMail(util.inspect(fields));\n        res.write(process.env.MESSAGE || 'Thank you for your submission.');\n        res.end();\n    });\n    form.parse(req);\n}\n\n// setup the email sender\n// uses the nodemailer lib\n// sends the email to the adress found in the `TO` env var\nlet transporter = nodemailer.createTransport({\n    host: process.env.EMAIL_HOST,\n    port: process.env.EMAIL_PORT,\n    secure: process.env.EMAIL_PORT === 465, // secure:true for port 465, secure:false for port 587\n    auth: {\n        user: process.env.EMAIL_USER,\n        pass: process.env.EMAIL_PASS\n    }\n});\n\nfunction sendMail(text) {\n  // setup email data with unicode symbols\n  let mailOptions = {\n      from: process.env.FROM || 'Email form data bot <no-reply@no-email.com>',\n      to: process.env.TO,\n      subject: 'New form submission' + (process.env.SITE_NAME ? ' on ' + process.env.SITE_NAME : ''),\n      text: text\n  };\n  console.log('sending email: ', mailOptions);\n  \n  // send mail with defined transport object\n  transporter.sendMail(mailOptions, (error, info) => {\n      if (error) {\n          return console.log(error);\n      }\n      console.log('Message %s sent: %s', info.messageId, info.response);\n  });\n}\n\n"]}