Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cors help? #29

Open
NicolasRondon opened this issue Mar 7, 2020 · 6 comments
Open

Cors help? #29

NicolasRondon opened this issue Mar 7, 2020 · 6 comments

Comments

@NicolasRondon
Copy link

http://localhost:8069/api/project.budget/ 405 (METHOD NOT ALLOWED)
Access to XMLHttpRequest at 'http://localhost:8069/api/project.budget/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I've made a vue app but when I want to create of records I got cors error
createProject() { const endpoint = 'http://localhost:8069/api/project.budget/' axios .post(endpoint, this.project, { headers: { session_id: '7951526a5f73527a5c1a7f4e21166d3844c3ddfc' } }) .then((response) => { console.log(response) }) }

@qnts
Copy link

qnts commented Jun 29, 2020

You might need to proxy the odoo endpoint. Check this stackoverflow problem:

https://stackoverflow.com/questions/57969766/not-able-to-set-proxy-port-in-my-vue-js-app

@pumppi
Copy link

pumppi commented Jan 17, 2021

Did you solve the method not allowed?

@luisangel-g
Copy link

I have the same problem, is there any solution ?, I already add cors = "*" to the controller but it doesn't work

@pumppi
Copy link

pumppi commented Aug 8, 2021

I Added nginx proxy front of odoo. Thats the solution.

@jeffryjdelarosa
Copy link

I Added nginx proxy front of odoo. Thats the solution.

Could can share it please. @pumppi

@pumppi
Copy link

pumppi commented Apr 18, 2022

Example code for docker nginx template. Nginx is front of odoo docker instance.

`events { worker_connections 1024; }

http {

client_max_body_size 500M;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
send_timeout 900;

#All the other odoo requests
upstream odoo {
server ${HOST_TO_PROXY}:8069;

}
#Odoo multiple workers enabled then redirect to here
upstream longpolling {
server ${HOST_TO_PROXY}:8072;
}

log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';

server {
listen 8080;
server_name localhost;

  access_log  /var/log/nginx/access.log upstreamlog;

  #Todo could be added other enviroments
  add_header 'Access-Control-Allow-Origin' $http_origin always;
  add_header 'Access-Control-Allow-Credentials' 'true';
  add_header 'Access-Control-Allow-Headers' 'Access-Control-Allow-Credentials,Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range, X-Openerp-Session-Id';
  add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';


  location / {
     proxy_pass http://odoo;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
     proxy_set_header Host $http_host;
     proxy_set_header X-NginX-Proxy true;
    
     proxy_cookie_path / "/; secure; HttpOnly; SameSite=none";

     if ($request_method = 'OPTIONS') {
       
        add_header 'Access-Control-Allow-Origin'  $http_origin always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        
        add_header 'Access-Control-Allow-Headers' 'Access-Control-Allow-Header,Access-Control-Allow-Credentials,Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,X-Openerp-Session-Id' always;
        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        
        return 204;
     }


  }

  location /longpolling {
     proxy_pass http://longpolling;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Proto $scheme;
     proxy_set_header Host $http_host;
     proxy_set_header X-NginX-Proxy true;
  }

}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants