Add nostore to upload healthcheck and fix double-sort

This commit is contained in:
Alan Grainger
2026-10-20 09:39:37 +13:00
parent fc7670157b
commit 6ae80569ff
10 changed files with 115 additions and 68 deletions
+3 -1
View File
@@ -38,10 +38,12 @@ export function abortOnClose (res: Response): AbortSignal {
}
/**
* A `GET /healthcheck` handler: `body` while Immich answers, else 503.
* A `GET /healthcheck` handler: `body` while Immich answers, else 503. Never
* cached, so a browser or CDN can't answer for a service that has gone.
*/
export function healthcheckHandler (body: string) {
return async (_req: Request, res: Response): Promise<void> => {
addNoStoreHeaders(res)
if (await accessible()) {
res.send(body)
} else {
+11 -1
View File
@@ -10,8 +10,9 @@ import * as client from '../src/immich/client'
*/
function response () {
const res = { body: undefined as string | undefined, code: 200 }
const res = { body: undefined as string | undefined, code: 200, headers: {} as Record<string, string> }
return Object.assign(res, {
set (name: string, value: string) { res.headers[name] = value; return res },
send (body?: string) { res.body = body; return res },
status (code: number) { res.code = code; return res }
})
@@ -36,6 +37,15 @@ describe('healthcheckHandler', () => {
expect(res.body).toBeUndefined()
})
it('is never cached, up or down', async () => {
for (const up of [true, false]) {
vi.spyOn(client, 'accessible').mockResolvedValue(up)
const res = response()
await healthcheckHandler('upload-ok')({} as never, res as never)
expect(res.headers['Cache-Control']).toContain('no-store')
}
})
it("is IPP's own healthcheck with `ok`", async () => {
vi.spyOn(client, 'accessible').mockResolvedValue(true)
const res = response()