1
0
Fork 0
mirror of https://github.com/alangrainger/immich-public-proxy.git synced 2024-12-28 03:41:58 +00:00

Update healthcheck

This commit is contained in:
Alan Grainger 2024-11-04 11:15:00 +01:00
parent be66b16a08
commit 4b0253f211
5 changed files with 34 additions and 21 deletions

View file

@ -1,5 +1,11 @@
FROM node:lts-slim
# Install wget for healthcheck
RUN apt-get update && \
apt-get install -y wget && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY app/ ./
@ -21,6 +27,6 @@ ENV NODE_ENV=production
# Type checking is done in the repo before building the image.
RUN npx tsc --noCheck
HEALTHCHECK --interval=30s --start-period=10s --timeout=5s CMD node /app/healthcheck.js || exit 1
HEALTHCHECK --interval=30s --start-period=10s --timeout=5s CMD wget -q http://localhost:3000/healthcheck || exit 1
CMD ["pm2-runtime", "dist/index.js" ]

View file

@ -1,9 +0,0 @@
(async () => {
try {
const res = await fetch('http://localhost:3000/healthcheck')
if (await res.text() === 'ok') {
process.exit(0)
}
} catch (e) { }
process.exit(1)
})()

View file

@ -11,17 +11,21 @@ class Immich {
* the possible attack surface of this app.
*/
async request (endpoint: string) {
const res = await fetch(process.env.IMMICH_URL + '/api' + endpoint)
if (res.status === 200) {
const contentType = res.headers.get('Content-Type') || ''
if (contentType.includes('application/json')) {
return res.json()
try {
const res = await fetch(process.env.IMMICH_URL + '/api' + endpoint)
if (res.status === 200) {
const contentType = res.headers.get('Content-Type') || ''
if (contentType.includes('application/json')) {
return res.json()
} else {
return res
}
} else {
return res
log('Immich API status ' + res.status)
console.log(await res.text())
}
} else {
log('Immich API status ' + res.status)
console.log(await res.text())
} catch (e) {
log('Unable to reach Immich on ' + process.env.IMMICH_URL)
}
}
@ -229,6 +233,10 @@ class Immich {
expires: dayjs().add(1, 'hour').format()
}))
}
async accessible () {
return !!(await immich.request('/server/ping'))
}
}
const immich = new Immich()

View file

@ -69,8 +69,12 @@ app.get('/:type(photo|video)/:key/:id', async (req, res) => {
})
// Healthcheck
app.get('/healthcheck', (_req, res) => {
res.send('ok')
app.get('/healthcheck', async (_req, res) => {
if (await immich.accessible()) {
res.send('ok')
} else {
res.status(502).send()
}
})
// Send a 404 for all other routes

View file

@ -6,3 +6,7 @@ services:
ports:
- ${PORT}:3000
env_file: .env
healthcheck:
test: wget -q http://localhost:3000/healthcheck || exit 1
start_period: 10s
timeout: 5s