binbytes / nuxt-chat-app

Frontend of real-time chat application built using nuxtjs, socket.io. Check the backend at https://github.com/binbytes/chat-app-server.

Home Page:https://chat.binbytes.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hi, i get problem about cors

Thaimay opened this issue · comments

I try run nuxt-chat-app and nuxt-chat-server then i get this error from client.
Please help me.

image

server i get this response

{ "res": { "statusCode": 200, "body": "POST" }, "req": { "url": "/api/auth/login", "headers": { "host": "localhost:3002", "connection": "keep-alive", "sec-fetch-mode": "cors", "access-control-request-method": "POST", "origin": "http://localhost:3000", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36", "access-control-request-headers": "content-type", "accept": "*/*", "sec-fetch-site": "same-site", "referer": "http://localhost:3000/login", "accept-encoding": "gzip, deflate, br", "accept-language": "vi-VN,vi;q=0.9,ja;q=0.8,en;q=0.7" }, "method": "OPTIONS", "httpVersion": "1.1", "originalUrl": "/api/auth/login", "query": {} }, "responseTime": 1, "level": "info", "message": "HTTP OPTIONS /api/auth/login 200 1ms" } OPTIONS /api/auth/login 200 0.444 ms - 4

@nikkanetiya nikkanetiya: Please help me

Hello @Thaimay

I recently tried it on my local machine and it working perfectly.

If you are change FRONT_ORIGIN on chat server then please do it with fronted.

or if you want to bypass things on development you can try chrome ext. this will solve cors issue on your browser.

Hello.
I have same issue at Chrome 74.0.3729.108 OS: Ubuntu 16.04

Access to XMLHttpRequest at 'localhost:3002/api/users/me' from origin 'http://localhost:3000' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

I solve this by adding protocol part to the api url
at fronted .env
change API_URL=localhost:3002/api
to API_URL=http://localhost:3002/api