Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/api/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ async function post(app: Hono<AppEnv>, path: string, body: unknown = {}): Promis
});
}

describe('root', () => {
test('the front door says what is running rather than 404ing', async () => {
const { app } = await harness('root-index');
const response = await app.request('/');

// The bug this replaces: pasting the hostname into a browser returned
// {"error":{"code":"not_found"}}, which reads as a broken deployment.
expect(response.status).toBe(200);
expect(await response.json()).toMatchObject({
service: 'api',
endpoints: { health: '/health/live', api: '/api/v1' },
});
});

test('an unknown path is still a 404', async () => {
const { app } = await harness('root-unknown');
const response = await app.request('/nope');

expect(response.status).toBe(404);
});
});

describe('health', () => {
test('liveness does not depend on the database', async () => {
const { app } = await harness('health-live');
Expand Down
19 changes: 19 additions & 0 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ export function createApp(options: AppOptions): Hono<AppEnv> {

app.use('*', cors());

// ------------------------------------------------------------------ root
// An API with no route at `/` answers the front door with a 404, which reads
// as "the deployment is broken" to anybody who pastes the hostname into a
// browser — including us. This says what is running and where to go instead.
app.get('/', (c) =>
c.json({
service: 'api',
name: 'outreachgraph',
version: options.version ?? '0.1.0',
...(options.commitHash ? { commitHash: options.commitHash } : {}),
docs: 'https://github.com/profullstack/outreachgraph',
endpoints: {
health: '/health/live',
ready: '/health/ready',
api: '/api/v1',
},
}),
);

// ---------------------------------------------------------------- health
// Two endpoints: liveness never touches the database so a database blip
// cannot cause Railway to kill a healthy process; readiness does.
Expand Down
Loading