Skip to content

Commit a638576

Browse files
committed
feat(app): Access to the ssr variable inside the ssr extension #4976
module.exports.extendApp = function ({ app, ssr }) {
1 parent e25879e commit a638576

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

app/lib/dev-server.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,37 @@ module.exports = class DevServer {
254254
maxAge: 0
255255
}))
256256

257-
SsrExtension.getModule().extendApp({ app })
257+
SsrExtension.getModule().extendApp({
258+
app,
259+
260+
ssr: {
261+
renderToString ({ req, res }, fn) {
262+
const context = {
263+
url: req.url,
264+
req,
265+
res
266+
}
267+
268+
renderer.renderToString(context, (err, html) => {
269+
if (err) {
270+
handleError(err)
271+
return
272+
}
273+
if (cfg.__meta) {
274+
html = context.$getMetaHTML(html)
275+
}
276+
277+
fn(err, html)
278+
})
279+
},
280+
281+
settings: Object.assign(
282+
{},
283+
JSON.parse(cfg.ssr.__templateOpts),
284+
{ debug: true }
285+
)
286+
}
287+
})
258288

259289
app.get('*', render)
260290
},

app/templates/ssr/extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* development server, but such updates are costly since the dev-server needs a reboot.
1212
*/
1313

14-
module.exports.extendApp = function ({ app }) {
14+
module.exports.extendApp = function ({ app, ssr }) {
1515
/*
1616
Extend the parts of the express app that you
1717
want to use with development server too.

app/templates/ssr/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (ssr.settings.pwa) {
3737
app.use('/', serve('.', true))
3838

3939
// we extend the custom common dev & prod parts here
40-
extension.extendApp({ app })
40+
extension.extendApp({ app, ssr })
4141

4242
// this should be last get(), rendering with SSR
4343
app.get('*', (req, res) => {

0 commit comments

Comments
 (0)