1
1
import Vue from 'vue'
2
- import VueServerRenderer from 'vue-server-renderer/build.js '
2
+ import { createRenderer } from 'vue-server-renderer'
3
3
import { WebApp } from 'meteor/webapp'
4
4
import cookieParser from 'cookie-parser'
5
5
import { onPageLoad } from 'meteor/server-render'
@@ -62,7 +62,7 @@ VueSSR.inSubscription = new Meteor.EnvironmentVariable() // <-- needed in data.j
62
62
63
63
patchSubscribeData ( VueSSR )
64
64
65
- const renderer = VueServerRenderer . createRenderer ( )
65
+ const renderer = createRenderer ( )
66
66
67
67
function writeServerError ( sink ) {
68
68
sink . appendToBody ( 'Server Error' )
@@ -91,24 +91,19 @@ onPageLoad(sink => new Promise((resolve, reject) => {
91
91
// }
92
92
93
93
// Vue
94
+ const context = { url : req . url }
94
95
let asyncResult
95
- const result = VueSSR . createApp ( { url : req . url } )
96
+ const result = VueSSR . createApp ( context )
96
97
if ( result && typeof result . then === 'function' ) {
97
98
asyncResult = result
98
99
} else {
99
100
asyncResult = Promise . resolve ( result )
100
101
}
101
102
102
- asyncResult . then ( result => {
103
- let app
104
- if ( result . app ) {
105
- app = result . app
106
- } else {
107
- app = result
108
- }
109
-
103
+ asyncResult . then ( app => {
110
104
renderer . renderToString (
111
105
app ,
106
+ context ,
112
107
( error , html ) => {
113
108
if ( error ) {
114
109
console . error ( error )
@@ -125,11 +120,11 @@ onPageLoad(sink => new Promise((resolve, reject) => {
125
120
// // sink.appendToHead(`<script type="text/inject-data">${encodeURIComponent(injectData)}</script>`)
126
121
127
122
let appendHtml
128
- if ( typeof result . appendHtml === "function" ) appendHtml = result . appendHtml ( )
123
+ if ( typeof context . appendHtml === "function" ) appendHtml = context . appendHtml ( )
129
124
130
- const head = ( ( appendHtml && appendHtml . head ) || result . head ) || ''
131
- const body = ( ( appendHtml && appendHtml . body ) || result . body ) || ''
132
- const js = ( ( appendHtml && appendHtml . js ) || result . js ) || ''
125
+ const head = ( ( appendHtml && appendHtml . head ) || context . head ) || ''
126
+ const body = ( ( appendHtml && appendHtml . body ) || context . body ) || ''
127
+ const js = ( ( appendHtml && appendHtml . js ) || context . js ) || ''
133
128
134
129
const script = js && `<script type="text/javascript">${ js } </script>`
135
130
0 commit comments