0

I have to set a parameter at cookies when user comes with an specific subdomain, actually there's a cookie.js script in middleware like:

export default function ({ app, res, query }) {
let uri = window.location.href.split('?');
if (uri[1]) {
    app.$cookies.set('pdv', query.pdv)
}}

I have to keep this feature, but when user comes from subdomain e.g: ask.exemple.com, automatically sets the PDV cookies as: 123.

E.g:

subdomain: ask / pdv: 123 subdomain: question / pdv: 456 ...

How can I do it?

kissu
  • 40,416
  • 14
  • 65
  • 133
  • see: [How to get a subdomain using window.location?](https://stackoverflow.com/questions/1201258/how-to-get-a-subdomain-using-window-location), then apply it to the code above – Lawrence Cherone Aug 22 '22 at 20:17
  • Thanks!! What do you think about it: export default function ({ app, res, query }) { let uri = window.location.href.split('?'); if (uri[1]) { app.$cookies.set('pdv', query.pdv) } let sub = window.location.host.split('.'); if (sub['confianca']) { app.$cookies.set('pdv', 'IMCI68') } else if (sub['metropole']) { app.$cookies.set('pdv', 'JK1TC7') } else if (sub['radiocultura']) { app.$cookies.set('pdv', 'J79KO9') } } – 97lcoutinho Aug 23 '22 at 14:42

0 Answers0