-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapi.ts
35 lines (26 loc) · 955 Bytes
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Hono } from 'hono';
import {
appCache,
langMw,
} from '@angular-love/blog-bff/shared/util-middleware';
import { ArrayResponse } from '@angular-love/blog-contracts/shared';
import { Page } from '@angular-love/blog/contracts/pages';
import { wpClientMw } from '@angular-love/util-wp';
import { toPage, toPageList } from './mappers';
import { WpPages } from './wp-pages';
const app = new Hono().use(appCache).use(wpClientMw).use(langMw());
app.get('/', async (c) => {
const client = new WpPages(c.var.createWPClient());
const result = await client.getPages();
return c.json(<ArrayResponse<Page>>{
data: toPageList(result.data),
total: Number(result.headers.get('x-wp-total')),
});
});
app.get('/:slug', async (c) => {
const slug = c.req.param('slug');
const client = new WpPages(c.var.createWPClient());
const result = await client.getBySlug(slug);
return c.json(toPage(result.data[0]));
});
export default app;