question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass global object from SSR extension.js to boot files

See original GitHub issue

Is there are any way to pass object from SSR extension.js to the boot file, so it can be used.

The idea: create a client, that can be used as a global object in SSR mode, on the low level there will be a clear cache URL, and in boot it will be used. Once I trigger /clear-cache object on the high level will be cleared.

I’ve checked this file (https://github.com/quasarframework/quasar/blob/dev/app/lib/dev-server.js#L232), seems like there are only context (app) object with req, res and url is passed to the boot loaders. Seems like there are no way to pass any object from express to vue app.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
justinbeatycommented, Jan 29, 2021

@dmitry You could probably attach it to the req object:

app.use(function (req, res, next) {
    req.client = getClient()
    next()
})

And get it in boot:

export default ({ store, ssrContext, redirect }) => {
  store.client = ssrContext.req.client
})

Which is maybe a bit hacky, but only way I can think of getting it to work in dev mode without modifying the core code.

In production, I believe you could do it right in index.js by passing another var into renderToString, but a quick look at the core code and I see no way to do it via dev mode.

ssr.renderToString({ req, res, client }, (err, html) => {
0reactions
dmitrycommented, Jan 29, 2021

Idea is something like that:

import getClient from 'client'

module.exports.extendApp = function ({ app, ssr }) {
  ssr.client = getClient()

  app.put('flush', function () {
    ssr.client.flushCache()
  })
})

Then in boot

export default ({ store, ssrContext, redirect }) => {
  store.client = ssrContext.client
})

And then access in Vue components through the store object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Boot files - Quasar Framework
A boot file is a simple JavaScript file which can optionally export a function. ... pass an object with the following properties to...
Read more >
Accessing global object from content script in chrome extension
I have defined a global object in a .js file. For example file1.js contains the global object SomeObject. This file gets loaded in...
Read more >
Server-Side Rendering (SSR) - Vue.js
Create a new directory and cd into it · Run npm init -y · Add "type": "module" in package.json so that Node.js runs...
Read more >
Server-side rendering (SSR) with Angular Universal
A Node.js Express web server compiles HTML pages with Universal based on client requests. To create the server-side application module, app.server.module ...
Read more >
How to Enable Server-Side Rendering for a React App
Server-side rendering (SSR) is a popular technique for rendering a client-side single ... Next, add the following code to the Home.js file:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found