Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

408
Views
bloqueado por la política CORS con nginx docker

Hola, estoy tratando de obtener datos de una API "restCountries" y está bloqueado por la política CORS. No entiendo por qué, he intentado establecer encabezados en el archivo index.php con la función header(), pero ha fallado.

Estoy trabajando con un archivo docker-compose "php, php-fpm, mysql, nginx"

Mi petición :

 const getlistOfAllCountries = async () => { // const myHeaders = new Headers() const responseFromWorldApi = await fetch("https://restcountries.com/v3.1/all", { method: 'POST', headers : { 'Access-Control-Allow-Origin' : '*', "Content-Type": "application/json" } }); const listOfAllCountries = await responseFromWorldApi.json(); }

mi archivo default.conf

 server { server_name ~.*; location / { root /usr/src/app; try_files $uri /index.php$is_args$args; } location ~ ^/.+\.php(/|$) { client_max_body_size 50m; fastcgi_pass php:9000; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/src/app/public$fastcgi_script_name; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; # # Om nom nom cookies # add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # # Custom headers and headers various browsers *should* be OK with but aren't # add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; # # Tell client that this pre-flight info is valid for 20 days # add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; } } error_log /dev/stderr debug; access_log /dev/stdout; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La API https://restcountries.com/v3.1/all no permite realizar el método POST. Actualice su método de POST a GET

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!