feat: add healthcheck endpoint
This commit is contained in:
@@ -31,7 +31,7 @@ RUN npm run build && npm prune --production
|
|||||||
# Stage 5: Final image
|
# Stage 5: Final image
|
||||||
FROM node:19-slim AS runner
|
FROM node:19-slim AS runner
|
||||||
ENV NODE_ENV=docker
|
ENV NODE_ENV=docker
|
||||||
RUN apt-get update && apt-get install -y openssl
|
RUN apt-get update && apt-get install -y curl openssl
|
||||||
|
|
||||||
WORKDIR /opt/app/frontend
|
WORKDIR /opt/app/frontend
|
||||||
COPY --from=frontend-builder /opt/app/public ./public
|
COPY --from=frontend-builder /opt/app/public ./public
|
||||||
@@ -47,4 +47,6 @@ COPY --from=backend-builder /opt/app/package.json ./
|
|||||||
|
|
||||||
WORKDIR /opt/app
|
WORKDIR /opt/app
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:3000/api/health || exit 1
|
||||||
|
|
||||||
CMD cp -rn /tmp/img /opt/app/frontend/public && node frontend/server.js & cd backend && npm run prod
|
CMD cp -rn /tmp/img /opt/app/frontend/public && node frontend/server.js & cd backend && npm run prod
|
||||||
14
frontend/src/pages/api/health.tsx
Normal file
14
frontend/src/pages/api/health.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import getConfig from "next/config";
|
||||||
|
|
||||||
|
const { apiURL } = getConfig().serverRuntimeConfig;
|
||||||
|
|
||||||
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
const apiStatus = await axios
|
||||||
|
.get(`${apiURL}/api/configs`)
|
||||||
|
.then(() => "OK")
|
||||||
|
.catch(() => "ERROR");
|
||||||
|
|
||||||
|
res.status(apiStatus == "OK" ? 200 : 500).send(apiStatus);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user