R
R
razer962018-09-19 12:08:07
Vue.js
razer96, 2018-09-19 12:08:07

What is the correct way to deal with request headers in Nuxt.js?

Hello.
Faced such a problem.
We are developing an online store on Nuxt.js, and now we are stuck on a problem with the cart.
In general, we have such a scheme. In My Vuex, a request is sent in the nuxtServerInit function for the state of the cart. The state of the cart is stored in the session on the server.
What is the actual problem.
It is necessary that there is a check that if I have cookies in my browser (the session key should be stored in the cookies), if there is, the request should be sent with the Cookie header, which will contain the session name and key.
Those. Now the problem is that when sending requests, axios simply ignores cookies, and does not unload the contents of cookies into headers. How to be prompt?
In general, is it necessary that the Naxt server init first check whether cookies are installed? If yes, then send via axios a Request that will already contain cookies, and if cookies are not set, then send a request via axios and then extract the session key from the response of this request and push it into cookies.
Or somehow set the headers at the Nginx config level???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hckn, 2018-09-19
@hckn

What is the practical point of generating a cart state for a particular user? Give it directly to the client, bypassing the ssr.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question