Merge pull request #426 from Crossbell-Box/feat/healthcheck

feat: healthcheck api
This commit is contained in:
Nya Candy 2023-04-25 11:10:09 +08:00 committed by GitHub
commit bc6d3db272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View File

@ -48,10 +48,11 @@ spec:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
readinessProbe:
tcpSocket:
httpGet:
path: /api/healthcheck
port: 3000
initialDelaySeconds: 40
periodSeconds: 10
periodSeconds: 20
livenessProbe:
tcpSocket:
port: 3000

View File

@ -64,10 +64,11 @@ spec:
- name: xlog-image
mountPath: /app/.next/cache/images
readinessProbe:
tcpSocket:
httpGet:
path: /api/healthcheck
port: 3000
initialDelaySeconds: 40
periodSeconds: 10
periodSeconds: 20
livenessProbe:
tcpSocket:
port: 3000

View File

@ -3,10 +3,15 @@ import { NextRequest, NextResponse } from "next/server"
import { IS_PROD } from "~/lib/constants"
import { DISCORD_LINK } from "~/lib/env"
// HTTPWhiteListPaths: White list of path for plain http request, no HTTPS redirect
const HTTPWhitelistPaths = [
"/api/healthcheck",
]
export default async function middleware(req: NextRequest) {
const { pathname } = req.nextUrl
if (IS_PROD && req.headers.get("x-forwarded-proto") !== "https") {
if (IS_PROD && req.headers.get("x-forwarded-proto") !== "https" && !HTTPWhitelistPaths.includes(req.nextUrl.pathname)) {
let cfHttps = false
try {
if (

View File

@ -0,0 +1,10 @@
import { NextApiRequest, NextApiResponse } from "next"
export default async function healthcheck(
req: NextApiRequest,
res: NextApiResponse,
) {
res.status(200).json({
ok: true,
})
}