【发布时间】:2021-10-04 06:21:27
【问题描述】:
我的 API 集群在 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,
});
}
这里的问题是,当 Kubernetes 上的部署尝试运行健康检查并在 origin 失败时,origin 返回未定义。 添加到我的白名单未定义值,它不起作用。
限制对我的 API 的访问的最佳方法是什么?
【问题讨论】:
-
速率限制,我猜。
标签: node.js kubernetes nestjs health-check