Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set custom healthcheck endpoint path + app healthcheck #497

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/mean-plums-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@hyperdx/api": patch
"@hyperdx/app": patch
---

Allow to set custom healthcheck endpoint path + app healthcheck
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ services:
REDIS_URL: redis://redis:6379
SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT}
USAGE_STATS_ENABLED: ${USAGE_STATS_ENABLED:-true}
HEALTHCHECK_PATH: '/health'
networks:
- internal
depends_on:
Expand All @@ -194,6 +195,7 @@ services:
HYPERDX_API_KEY: ${HYPERDX_API_KEY}
NODE_ENV: development
PORT: ${HYPERDX_APP_PORT}
HEALTHCHECK_PATH: '/health'
networks:
- internal
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routers/api/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const registrationSchema = z

const router = express.Router();

router.get('/health', async (req, res) => {
router.get(process.env.HEALTHCHECK_PATH || '/health', async (req, res) => {
res.send({ data: 'OK', version: config.CODE_VERSION, ip: req.ip });
});

Expand Down
7 changes: 4 additions & 3 deletions packages/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ ENV NEXT_PUBLIC_OTEL_SERVICE_NAME $OTEL_SERVICE_NAME
ENV NEXT_PUBLIC_SERVER_URL $SERVER_URL

COPY ./packages/app/tsconfig.json ./packages/app/next.config.js ./packages/app/mdx.d.ts ./packages/app/.eslintrc.js ./
COPY ./packages/app/src ./src
COPY ./packages/app/pages ./pages
COPY ./packages/app/public ./public
COPY ./packages/app/middleware.ts ./
COPY ./packages/app/src ./src
COPY ./packages/app/pages ./pages
COPY ./packages/app/public ./public
COPY ./packages/app/styles ./styles
COPY --from=base /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
Expand Down
12 changes: 12 additions & 0 deletions packages/app/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';

const healthCheckUrl = process.env.HEALTHCHECK_PATH || '/health';

export function middleware(request: NextRequest) {
if (healthCheckUrl === request.nextUrl.pathname) {
return NextResponse.json({ data: 'ok' }, { status: 200 });
}

return NextResponse.next();
}
2 changes: 1 addition & 1 deletion packages/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"@styles/*": ["styles/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "middleware.ts"],
"exclude": ["node_modules"]
}