Wednesday 25 December 2019

I'm getting "origin" undefined at CORS middleware

This is the middleware: private middlewares (): void { this.express.use(express.json()) const whiteList = ['http://127.0.0.1:8020', 'http://localhost:5000'] const corsOptions = { origin: (origin, callback) => { if (!!origin || whiteList.indexOf(origin) !== -1) { console.log(origin, 'rosrcharc') callback(null, true) } else { console.log(origin, 'moralmente') callback(new Error('Not allowed by CORS')) } } } this.express.use(cors(corsOptions)) } Always get's at the 'else' even tough 5000 is the correct server. I noticed that origin parameter is undefined. What can i do?

Submitted December 26, 2019 at 12:26AM by danilosilvadev

No comments:

Post a Comment