0

I'm trying to pre-render metas with google cloud functions but I can't figure out how to acces the values, the data log returns this on the functions console (see link)

console.log(data) returns this

    exports.preLoadMeta = functions.https.onRequest((request, response) => {
    let id = request.url.split("/");
    let data;

    admin.database().ref('proyectos').orderByChild("urlAmigable").equalTo(id[2]).once("value")
        .then(proyectos =>{
            data = proyectos.val();
            console.log(data)
        }).then( () => {
            response.status(200).send(`
<!doctype html>
<html class="no-js" lang="es" dir="ltr">
  <head>
    <title>${data.titulo}</title>
    <meta name="description" content="bla bla - ${data.titulo}" />
    <meta property="og:title" content="${data.titulo}" />
    <meta property="og:description" content="${data.meta}" />
    <meta property="og:image" content="${data.imgUrl}" />
    <meta property="og:type" content="article" />
            `);
        })
})

(this does not work)

1 Answer 1

2

I think you're expecting your query to return the child instead of the collection. You need to get the child (even though there's only one in this case). Try using this code for your snapshot instead:

proyectos.forEach(child => {
  data = child.val()
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.