Update healthcheck
This commit is contained in:
@@ -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)
|
||||
})()
|
||||
+17
-9
@@ -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()
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user