'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'

前端 未结 1 1981
广开言路
广开言路 2020-12-10 01:50

I\'m using node, express on backend and angular4 at client side which is giving me following error:

XMLHttpRequest cannot load http://localhost:4876/l

相关标签:
1条回答
  • 2020-12-10 02:35

    While setting cors in corsOptions I added value credentials true it worked as follows:

    private setCors(){
            let whitelist = ['http://localhost:4200','http://localhost:80'];
            let corsOptions = {
                origin: (origin:any, callback:any)=>{
                    if (whitelist.indexOf(origin) !== -1) {
                        callback(null, true)
                    } else {
                        callback(new Error('Not allowed by CORS'))
                    }
                },credentials: true
            }
            this.app.use(cors(corsOptions));
        }
    
    0 讨论(0)
提交回复
热议问题