Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true #170

@Sachin-Suresh

Description

@Sachin-Suresh

Im trying to interact angular 2 with node js and below is my cors headers configured in index.js of nodejs

app.use(function(req, res, next) { 
        res.setHeader("Access-Control-Allow-Methods", "POST, PUT, OPTIONS, DELETE, GET");
        res.header("Access-Control-Allow-Origin", "http://localhost:4200");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        //res.header("Access-Control-Allow-Credentials", false);
        next();
});

app.use(cors({ origin: 'http://localhost:4200' }));   //If i use this it works
app.use(cors({ origin: '*' }));     //But i want to keep it as *

I have not anywhere configured CORS nor set withCredentials to True, where is my setting wrong?

How to avoid this error

Error stack:

XMLHttpRequest cannot load http://localhost:5000/upload. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:4200' is therefore not allowed access.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions