diff --git a/deploy/dev/sts.yaml b/deploy/dev/sts.yaml index 53171c82..e4df3f35 100644 --- a/deploy/dev/sts.yaml +++ b/deploy/dev/sts.yaml @@ -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 diff --git a/deploy/prod/deploy.yaml b/deploy/prod/deploy.yaml index 1cd7d1f5..f8b40810 100644 --- a/deploy/prod/deploy.yaml +++ b/deploy/prod/deploy.yaml @@ -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 diff --git a/src/middleware.ts b/src/middleware.ts index 864d3d32..79349b2f 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -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 ( diff --git a/src/pages/api/healthcheck.ts b/src/pages/api/healthcheck.ts new file mode 100644 index 00000000..52f5b68c --- /dev/null +++ b/src/pages/api/healthcheck.ts @@ -0,0 +1,10 @@ +import { NextApiRequest, NextApiResponse } from "next" + +export default async function healthcheck( + req: NextApiRequest, + res: NextApiResponse, +) { + res.status(200).json({ + ok: true, + }) +}