Estoy usando una función sin servidor de DigitalOcean, pero no estoy seguro de cómo generar HTML; solo puedo hacer que se imprima en la consola.
const http = require('http'); const url = require('url'); const metascraper = require('metascraper')([ require('metascraper-title')() ]) const got = require('got'); exports.main = (args) => { const targetUrl = "https://facebook.com"; (async () => { res.setHeader("Content-Type", "application/json; charset=utf-8"); try { const { body: html, url } = await got(targetUrl).catch(error => console.error(error)); const metadata = await metascraper({ html, url }).catch(error => console.error(error)); res.end("<h1>Print test</h1>"); // Return the metadata as JSON console.log(JSON.stringify(metadata)); } catch (err) { console.log(err); } })() } El error es que UnhandledPromiseRejectionWarning: ReferenceError: res is not defined
En el ejemplo proporcionado por DigitalOcean, así es como pueden generar texto:
exports.main = (args) => { return qrcode.toDataURL(args.text).then(res => ({ headers: { 'content-type': 'text/html; charset=UTF-8' }, body: args.img == undefined ? res : `<img src="${res}">` })) } He intentado usar el .then(res... también lo usaron en el ejemplo pero tampoco funciona
¿Cómo puedo hacer que el texto se envíe al documento? No estoy usando express ni nada, solo modifiqué el ejemplo proporcionado por DigitalOcean para que funcione con mis propios módulos: esta es una función sin servidor