Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR how to set defaultBreakpoint value according to serverMiddleware function? #40

Open
Manieck opened this issue Oct 3, 2019 · 1 comment

Comments

@Manieck
Copy link

Manieck commented Oct 3, 2019

Hi All

I can't find a solution for this for a long time.

I have serverMiddleware function:

device-detect.js

import parser from 'ua-parser-js';

export default (req, res, next) => {
  const ua = parser(req.headers['user-agent']);
  console.log(ua.device.type);  // returns: console, mobile, tablet, smarttv, wearable, embedded
  req.device = ua.device.type;  // I tried by req
  next();
}

nuxt.config.js

serverMiddleware: [
    '~/server_middlewares/device-detect.js'
  ]

And now I would like to set the defaultBreakpoint value in accordance with what this function decodes in plugin
media-query.js

import Vue from 'vue';
import VueMq from 'vue-mq';

Vue.use(VueMq, {
  breakpoints: { // default breakpoints - customize this
    phone: 500,
    tablet: 700,
    desktop: Infinity
  },
  defaultBreakpoint:  // < How to set it according to the function device-detect.js  
})

Thanks to this, we will avoid generating SSR incompatible with the device.

Do you have any ideas how to do it?

Thx

@JoeDaku
Copy link

JoeDaku commented Jun 29, 2020

I would also love for this to be configureable and not static.
Perhaps it could support a function? I'm also using Nuxt. Maybe the wrapping Nuxt module could then pass the context to that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants