2023-02-03 06:40:02 +00:00
|
|
|
import { json } from '@sveltejs/kit';
|
|
|
|
|
import type { RequestHandler, RequestEvent } from './$types';
|
|
|
|
|
import { fetchArticlesApi } from '$root/routes/api';
|
|
|
|
|
|
2023-02-10 00:25:21 +00:00
|
|
|
export const GET: RequestHandler = async ({ url, setHeaders }: RequestEvent) => {
|
2023-02-03 06:40:02 +00:00
|
|
|
try {
|
2023-02-10 00:25:21 +00:00
|
|
|
const response = await fetchArticlesApi('get', `fetchArticles`, {
|
|
|
|
|
page: url?.searchParams?.get('page') || '1'
|
|
|
|
|
});
|
2023-02-03 06:40:02 +00:00
|
|
|
|
|
|
|
|
if (response?.articles) {
|
|
|
|
|
setHeaders({
|
2023-02-10 00:25:21 +00:00
|
|
|
'cache-control': 'max-age=60'
|
2023-02-03 06:40:02 +00:00
|
|
|
});
|
|
|
|
|
|
2023-02-10 00:25:21 +00:00
|
|
|
// const articlesResponse = response.articles;
|
|
|
|
|
// console.log(`Found articles ${articlesResponse?.articles?.length}`);
|
|
|
|
|
// const articles = [];
|
2023-02-03 06:40:02 +00:00
|
|
|
|
2023-02-10 00:25:21 +00:00
|
|
|
// for (const article of articlesResponse) {
|
|
|
|
|
// const { tags, title, url, hashed_url, reading_time, preview_picture } = article;
|
|
|
|
|
// articles.push({ tags, title, url, hashed_url, reading_time, preview_picture });
|
|
|
|
|
// }
|
2023-02-03 06:40:02 +00:00
|
|
|
|
2023-02-10 00:25:21 +00:00
|
|
|
return json(response);
|
2023-02-03 06:40:02 +00:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|