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

238
Views
Enviar axios fetch al nombre de dominio y volver a enviarlo a la API

Quiero resolver un problema con react native y iphone. Tengo API en Gcloud, digamos ip 34.xx.xx.xx, y un nombre de dominio myapp.com. En el nombre de dominio myapp.com tengo un certificado SSL y https, en la dirección IP tengo un servidor nginx con https pero sin certificado. ¿Qué puedo hacer para que axios obtenga una solicitud de mi nombre de dominio, sin obtener errores CORS, etc.

Una forma en que resolví el problema con CORS es la configuración de nginx:

 # Wide-open CORS config for nginx # location / { 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'; } if ($request_method = 'GET') { 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'; } }

Con esta configuración, los errores de CORS desaparecieron, la API dejó de enviar datos y en Postman aparece este error: Captura de pantalla de error de Postman

Y esta es la solicitud de búsqueda:

 axios.post(`${Ip}login`, { email: email, password: password }, {headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }) .then(function (response) { const stringToken = String(response.data.access_token) setToken(stringToken) sighIn(stringToken) setLoading(false) }) .catch(function (error) { console.log("login section")
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

puedes usar la función de creación de axios

 const instance = axios.create({ baseURL: 'https://myapp.com', headers: { 'any': 'any' }, timeout: 1000, }); instance.get("/any")
over 4 years ago · Santiago Trujillo 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!