-
Notifications
You must be signed in to change notification settings - Fork 19
/
hash.ts
31 lines (27 loc) · 832 Bytes
/
hash.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
import { NextApiRequest, NextApiResponse } from "next";
import { Client } from "@notionhq/client";
import { encode } from "../../utils/codec";
const databaseId = process.env.NOTION_DATABASE_ID;
const notion = new Client({ auth: process.env.NOTION_API_KEY });
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const db = await notion.databases.query({
database_id: databaseId,
sorts: [
{
property: "Date",
direction: "descending",
},
],
});
const entry = db.results[0] as any;
const date = entry.properties.Date.date.start;
const word = entry.properties.Word.title[0].plain_text;
res.setHeader(
"Cache-Control",
"public, s-maxage=60, stale-while-revalidate=3600"
);
res.status(200).json({ hash: encode(word), date: date });
}