Nuxt socket.io CORS error
Hi, if I have a nuxt application behind a reverse proxy (nginx), should I set up CORS only in nginx or also in nuxt?
18 Replies
im running an app behind reverse proxy as well, i dont remember setting anything specifically for cors
you must have set something up, although maybe not cors
cors is needed if you want to access the server from a different address than the one where nuxt is running
i found this as an example
i found that too, but it doesnt answer my question
oh yea
just nginx should be fine
But normally it would be necessary to configure the allowed origins in nuxt. Why doesn't it have to be done there if it is previously in nginx?
i mean it doesnt matter as long as you set the headers, if you set them in nuxt nginx will forward it straight, if you set them in nginx it will just add the headers to the response. output is gonna be the same, i think
if i set them in nuxt, it doesnt work
because nginx is blocking it
nginx.conf:
do i need to setup it somehow to allow nginx to forward the nuxt cors headers?
well you are not sending your nginx conf or any code, so all i can do is guess
oh nvm
you mean the whole request or just the headers?
i mean that i get the cors origin error in console when trying to connect to websocket
with configured cors origin in nuxt
well you are gonna get the cors error if the clients get 4xx/5xx responses as well
its this error in console
from origin 'http://localhost:3000/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
check the network tab
for what should i look there?
status codes, nuxt errors, nginx errors
you can also check nginx logs to see whats up
@Archerist I tried it on localhost with different ports and the error is same
is there something wrong?
this runs on port 8000 and frontend on port 3000 so i am allowing that origin
so you have engine io server, socket io server, http server and nitro server all at the same time?
well this is outside of my knowledge sorry