• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

2.1K
Views
Problema CORS - preflightMissingAllowOriginHeader - Express Gateway y Axios

Estoy tratando de usar Express Gateway + AXIOS (react) + Express, pero estoy recibiendo el CORS Erro, ya hice muchas cosas pero nada funcionó.

El error es este: ingrese la descripción de la imagen aquí

Cross-Origin Resource Sharing error: PreflightMissingAllowOriginHeader

Mi EXPRESS es así:

 const corsOptions = { origin: '*', methods: ['POST', 'GET', 'PATCH', 'DELETE'], allowedHeaders: ['Content-Type', 'Authorization'] } app.use(cors(corsOptions));

Mi EXPRESS-GATEWAY :

 http: port: 8080 admin: port: 9876 host: localhost apiEndpoints: api: host: "localhost" paths: - '/api/B/*' - '/api/A/*' serviceEndpoints: appname: urls: - 'http://localhost:8000' policies: - jwt - cors - expression - log - proxy - rate-limit pipelines: default: apiEndpoints: - api policies: - cors: - action: origin: ["*"] methods: [ "HEAD", "PUT", "PATCH", "POST", "GET", "DELETE" ] credentials: true allowedHeaders: ['Content-type','Authorization','Origin','Access-Control-Allow-Origin','Accept','Options','X-Requested-With'] - jwt: - action: secretOrPublicKey: code checkCredentialExistence: false - proxy: - action: serviceEndpoint: appname changeOrigin: true

Mi AXIOS :

 const headers = { headers: { "Authorization": authToken, "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": true }, } axios.get(`${API_PRIVATE_URL}/user/profile`, { crossdomain: true }, { withCredentials: true }, headers)

Ya no sé qué hacer. Alguien me puede ayudar ?

Ya entré en varias publicaciones pero nada funcionó..

editar: tampoco fue al controlador. edit2: Puedo usar con POSTMAN, y funcionó como se esperaba...

over 3 years ago · Santiago Trujillo
1 answers
Answer question

0

Agregue "OPCIONES" después de "ELIMINAR" en sus listas de métodos permitidos en express/express-gateway.

 const corsOptions = { origin: '*', methods: ['POST', 'GET', 'PATCH', 'DELETE', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization'] } app.use(cors(corsOptions));

 http: port: 8080 admin: port: 9876 host: localhost apiEndpoints: api: host: "localhost" paths: - '/api/B/*' - '/api/A/*' serviceEndpoints: appname: urls: - 'http://localhost:8000' policies: - jwt - cors - expression - log - proxy - rate-limit pipelines: default: apiEndpoints: - api policies: - cors: - action: origin: ["*"] methods: [ "HEAD", "PUT", "PATCH", "POST", "GET", "DELETE", "OPTIONS" ] credentials: true allowedHeaders: ['Content-type','Authorization','Origin','Access-Control-Allow-Origin','Accept','Options','X-Requested-With'] - jwt: - action: secretOrPublicKey: code checkCredentialExistence: false - proxy: - action: serviceEndpoint: appname changeOrigin: true

over 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error