Skip to content

Commit b87c4f3

Browse files
authored
Merge pull request #39 from piyook/chore/add-api-list
chore(): add /api route
2 parents 69a75e7 + e321188 commit b87c4f3

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import getApiRoutes from './utilities/file-scan.js';
55
import serverPage from './utilities/server-page.js';
66
import logPage from './utilities/log-page.js';
77
import { deleteLogs } from './utilities/logger.js';
8+
import { apiList } from './utilities/api-list.js';
89
import { env } from './utilities/env.js';
910

1011
const { apiHandlers, apiRoutes } = await getApiRoutes();
@@ -13,6 +14,7 @@ const httpServer = createServer(
1314
...apiHandlers,
1415
...serverPage(apiRoutes),
1516
...logPage(),
17+
...apiList(apiRoutes),
1618
);
1719

1820
// Delete any logs on server start if the DELETE_LOGS_ON_SERVER_RESTART env var is set to 'ON'

src/utilities/api-list.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { http, HttpResponse } from 'msw';
2+
import { prefix } from './env';
3+
const apiList = (apiList: string[] = ['1', '2', '3']) => [
4+
http.get(`/api`, () => {
5+
const apiPaths = apiList.map((path) => `/${prefix}${path}`);
6+
return HttpResponse.json(apiPaths);
7+
}),
8+
];
9+
10+
export { apiList };

src/utilities/server-page.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,10 @@ const homePage = (apiPaths: string[]) => [
509509
});
510510
}),
511511
http.get(`/ping`, () => {
512-
return new HttpResponse(null, { status: 200 });
512+
return HttpResponse.json(
513+
{ response: 'server is running' },
514+
{ status: 200 },
515+
);
513516
}),
514517
];
515518

0 commit comments

Comments
 (0)