mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-11-04 23:10:13 +01:00
feat: add healthcheck endpoint
This commit is contained in:
parent
e5071cba12
commit
5132d177b8
@ -31,7 +31,7 @@ RUN npm run build && npm prune --production
|
||||
# Stage 5: Final image
|
||||
FROM node:19-slim AS runner
|
||||
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
|
||||
COPY --from=frontend-builder /opt/app/public ./public
|
||||
@ -47,4 +47,6 @@ COPY --from=backend-builder /opt/app/package.json ./
|
||||
|
||||
WORKDIR /opt/app
|
||||
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
|
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);
|
||||
};
|
Loading…
Reference in New Issue
Block a user