1
app.use(function (req, res, next) {

    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8100');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', '*');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});

I use postman everything work fine but I got CORS issue when testing my ionic app which it runs at http://localhost:8100. I googled and manage to find above set header solution but now I'm getting this error :

Request header field owner is not allowed by Access-Control-Allow-Headers in preflight response.

Any thought?

4

1 Answer 1

1

Try using the cors middleware.

var cors = require('cors');

app.use(cors());

Not the answer you're looking for? Browse other questions tagged or ask your own question.