Problems with cors

Discussão em 'Angular' iniciado por Axel15, Outubro 29, 2024.

  1. Axel15

    Axel15 Guest

    I'm developping an app using Ionic Angular which has front and back, but when i try to do a fetch to get some items from the database, i got an error that says: "Cross-origin request blocked: The same-origin policy does not allow reading the remote resource at https://localhost:3700/api/productid/1. (Reason: CORS request failed.) Status code: (null)." The problem is that i've installed the cors package, and then i've imported it via var cors = require('cors') and app.use(cors()); , so I really dont understand what else to do, also tried:

    app.use(cors({ allowedHeaders: ["authorization", "Content-Type"], // you can change the headers exposedHeaders: ["authorization"], // you can change the headers origin: "*", methods: "GET,HEAD,PUT,PATCH,POST,DELETE", preflightContinue: false }); );

    this also didnt work

    As ive said, tried installing cors, importing it using only var cors = require('cors') and app.use(cors()). Then using it like:

    app.use(cors({allowedHeaders: ["authorization", "Content-Type"], // you can change the headers exposedHeaders: ["authorization"], // you can change the headers origin: "*", methods: "GET,HEAD,PUT,PATCH,POST,DELETE", preflightContinue: false }); );

    Used multiple browsers (Firefox, Chrome, Edge, Opera).

    As expected, when I try to call the backend using postman I get the correct response

    Continue reading...

Compartilhe esta Página