From 7f47f2c83a646f55e651c396e8aa1719821dbd2b Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Tue, 25 Apr 2023 10:12:10 +0800 Subject: [PATCH 1/3] feat: healthcheck api --- src/pages/api/healthcheck.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/pages/api/healthcheck.ts 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, + }) +} From cdd111036a453674482033f46cf16167cf2fdb8f Mon Sep 17 00:00:00 2001 From: sljeff Date: Tue, 25 Apr 2023 10:49:57 +0800 Subject: [PATCH 2/3] chore: health check deploy --- deploy/dev/sts.yaml | 5 +++-- deploy/prod/deploy.yaml | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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 From 41938cac88d844e606e580e00b22b783da9f5794 Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Tue, 25 Apr 2023 11:03:45 +0800 Subject: [PATCH 3/3] feat: add http no redirect list for specific paths --- src/middleware.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 (