My API cluster is under kubernetes.
if (!configService.isProduction()) {
app.enableCors();
} else {
const whitelist = ['https://sub. domain .com', 'https:// www.domain .com', 'undefined'];
app.enableCors({
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
console.log("allowed cors for:", origin)
callback(null, true)
} else {
console.log("blocked cors for:", origin)
callback(new Error('Not allowed by CORS'))
}
},
allowedHeaders: 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, Observe',
methods: "GET,PUT,POST,DELETE,UPDATE,OPTIONS",
credentials: true,
});
}
The problem here is when the deployment up Kubernetes try to run a health check and fails at origin, origin return as undefined. Added to my whitelist undefined value, it didn't work.
What is the best way to limit access to my API?