W
W
webe2018-06-22 07:52:10
Nginx
webe, 2018-06-22 07:52:10

How to bypass CORS?

1) I raised the API service on the node, port 5000.
I access it like this:
127.0.0.1:5000/api/v1/categories/all
2) the client is launched at 127.0.0.1:81 and it sends an AJAX request to our server.
swears at CORS
Tell me pliz how to do it right so that I don’t swear at CORS?
Maybe some kind of proxying on the node or NGINX is there?
I got it through Access-Control-Allow-Origin, but I would like somehow without this header ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-06-22
@webe

Solving the problem with nginx .
Write the application host in /etc/hosts :
In nginx.conf in the server section :

server {
  listen 80;
  server_name my-app;

  location ^~ / {
    proxy_pass http://localhost:81/;
  }
  location ^~ /api/ {
    proxy_pass http://localhost:5000/api/;
  }
}

Refer to the application in the browser as a http://my-appand to the API in the application as http://my-app/api.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question