Skip to content

Commit

Permalink
chore: hide detail props from health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Nov 25, 2024
1 parent 50989f3 commit d7b5211
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
19 changes: 5 additions & 14 deletions server/api/health/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ const throwCustomError = (label: string) => (e: Error) => {
export default defineController(() => ({
get: async () => ({
status: 200,
body: {
server: 'ok',
db: await prismaClient.$queryRaw`SELECT CURRENT_TIMESTAMP;`
.then(() => 'ok' as const)
.catch(throwCustomError('DB')),
s3: await s3
.health()
.then(() => 'ok' as const)
.catch(throwCustomError('S3')),
cognito: await cognito
.health()
.then(() => 'ok' as const)
.catch(throwCustomError('Cognito')),
},
body: await Promise.all([
prismaClient.$queryRaw`SELECT CURRENT_TIMESTAMP;`.catch(throwCustomError('DB')),
s3.health().catch(throwCustomError('S3')),
cognito.health().catch(throwCustomError('Cognito')),
]).then(() => 'ok'),
}),
}));
2 changes: 1 addition & 1 deletion server/api/health/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import type { DefineMethods } from 'aspida';

export type Methods = DefineMethods<{
get: {
resBody: Record<'server' | 'db' | 's3' | 'cognito', 'ok'>;
resBody: 'ok';
};
}>;
4 changes: 1 addition & 3 deletions server/tests/api/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ test(GET(noCookieClient.health), async () => {
const apiClient = await createCognitoUserClient();
const res = await apiClient.health.$get();

expect(res.server).toEqual('ok');
expect(res.db).toEqual('ok');
expect(res.s3).toEqual('ok');
expect(res).toEqual('ok');
});

test(POST(noCookieClient.session), async () => {
Expand Down

0 comments on commit d7b5211

Please sign in to comment.