Browse Source
- Added constants for common cloud probe paths and prefixes. - Introduced middleware to handle cloud probe requests with appropriate cache control headers. - Updated Nuxt configuration to include route rules for cloud probe paths. This enhances the application's ability to respond to health checks from various cloud platforms.tags/邮箱功能前置
4 changed files with 90 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,42 @@ |
|||||
|
/** |
||||
|
* 各云平台 / 容器编排常见 HTTP 探针路径(不含 `/`,避免误伤站点根)。 |
||||
|
* 可按负载均衡控制台实际配置增删;若与业务路由同名请从列表中移除对应项。 |
||||
|
*/ |
||||
|
export const CLOUD_PROBE_PATHS = [ |
||||
|
// 通用 / Kubernetes
|
||||
|
"/health", |
||||
|
"/healthz", |
||||
|
"/livez", |
||||
|
"/readyz", |
||||
|
"/liveness", |
||||
|
"/readiness", |
||||
|
"/startup", |
||||
|
"/health/live", |
||||
|
"/health/ready", |
||||
|
"/health/startup", |
||||
|
// Spring Actuator(经网关暴露时偶见)
|
||||
|
"/actuator/health", |
||||
|
"/actuator/health/liveness", |
||||
|
"/actuator/health/readiness", |
||||
|
// Azure App Service 相关默认探测
|
||||
|
"/robots933456.txt", |
||||
|
// 国内云控制台常见示例静态页
|
||||
|
"/check.html", |
||||
|
"/status.html", |
||||
|
"/ping", |
||||
|
"/status", |
||||
|
"/alive", |
||||
|
] as const; |
||||
|
|
||||
|
/** 阿里云等:健康检查为 `/rpc` 或带后缀路径(如控制台填写的 `/rpc/...`),按前缀匹配 */ |
||||
|
export const CLOUD_PROBE_PATH_PREFIXES = ["/rpc"] as const; |
||||
|
|
||||
|
export const CLOUD_PROBE_PATH_SET = new Set<string>(CLOUD_PROBE_PATHS); |
||||
|
|
||||
|
export function isCloudProbePath(pathname: string): boolean { |
||||
|
if (CLOUD_PROBE_PATH_SET.has(pathname)) return true; |
||||
|
for (const prefix of CLOUD_PROBE_PATH_PREFIXES) { |
||||
|
if (pathname === prefix || pathname.startsWith(`${prefix}/`)) return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
import { getRequestURL } from "h3"; |
||||
|
import { isCloudProbePath } from "#server/constants/cloud-probes"; |
||||
|
|
||||
|
const METHODS = new Set(["GET", "HEAD"]); |
||||
|
|
||||
|
export default eventHandler((event) => { |
||||
|
if (!METHODS.has(event.method)) return; |
||||
|
|
||||
|
const pathname = getRequestURL(event).pathname; |
||||
|
if (!isCloudProbePath(pathname)) return; |
||||
|
|
||||
|
setHeader(event, "content-type", "text/plain; charset=utf-8"); |
||||
|
setHeader( |
||||
|
event, |
||||
|
"cache-control", |
||||
|
"no-store, no-cache, must-revalidate, proxy-revalidate", |
||||
|
); |
||||
|
|
||||
|
if (event.method === "HEAD") { |
||||
|
setResponseStatus(event, 200); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
return "OK"; |
||||
|
}); |
||||
Loading…
Reference in new issue