meteor-vue / vue-meteor

🌠 Vue first-class integration in Meteor
897 stars 112 forks source link

Add head and body append to vue-ssr createApp #300

Closed marsimeau closed 6 years ago

marsimeau commented 6 years ago

It is currently impossible to append html to head or body tags using vue-ssr package's VueSSR.createApp. In order to allow packages such as vue-meta to work in SSR, I have made these changes:

Here is an example of what would be possible with these changes:

VueSSR.createApp = function (context) {
  return new Promise((resolve, reject) => {
    const { app, router, store } = createApp()

    router.push(context.url)
    context.meta = app.$meta()

    // ...

    resolve({
      app,
      appendHtml() {
        const {
          title, link, style, script, noscript, meta
        } = context.meta.inject()

        return {
          head: `
            ${meta.text()}
            ${title.text()}
            ${link.text()}
            ${style.text()}
            ${script.text()}
            ${noscript.text()}
          `,
          body: script.text({ body: true })
        }
      }
    })
  })
}

Partially fixes #149. As far as I know, Meteor doesn't allow html or body attributes to be edited on the server.