functions/showLolly.js const faunadb = require(‘faunadb’); const pageTemplate = require(‘./lollyTemplate.js’); // setup and auth the Fauna DB client const q = faunadb.query; const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET }); // Create a handler function to export const handler = async(event) =>” { // get the lolly ID from the request let lollyId = event.path.split(“lolly/”)[1]; // find the lolly data in the DB client.query( q.Get(q.Match(q.Index(“lolly_by_path”), lollyId)) ).then((response) =>” { // if found, return a view return { statusCode: 200, headers: { “Content-Type”: “text/html”, }, body: pageTemplate(response.data) } }).catch((error) =>” { // not found or an error, send to the generic error page }); } // export the handler function exports.handler = handler;
@philhawksworth
// if found, return a view return { statusCode: 200, headers: { “Content-Type”: “text/html”, }, body: pageTemplate(response.data) }