Skip to content

Commit

Permalink
qiita apiのリクエスト時にQIITA_API_TOKEN環境変数があればそれをBearerトークンに指定するように
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Feb 3, 2024
1 parent 2fb9a20 commit 70e5756
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/lib/src/crawler/qiita.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ const qiitaApiSchema = z.object({
rendered_body: z.string(),
});

const apiToken = process.env.QIITA_API_TOKEN;

export const fetchArticleFromQiita = async (url: string) => {
const { pathname } = new URL(url);
const key = pathname.split('/').slice(-1)[0];

const apiResponse = await fetch(`https://qiita.com/api/v2/items/${key}`);
const apiResponse = await fetch(`https://qiita.com/api/v2/items/${key}`, {
headers: { Authorization: apiToken ? `Bearer ${apiToken}` : '' },
});
const query = qiitaApiSchema.parse(await apiResponse.json());

const { title, rendered_body: body } = query;
Expand Down

0 comments on commit 70e5756

Please sign in to comment.