[chore] Switch Homepage and Photos to page endpoints

This commit is contained in:
2022-05-30 20:47:31 +02:00
parent 9792165272
commit c406278baf
4 changed files with 124 additions and 120 deletions

39
src/routes/index.ts Normal file
View File

@@ -0,0 +1,39 @@
import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit'
import { fetchAPI } from '$utils/api'
export async function get({}: RequestEvent): Promise<RequestHandlerOutput> {
try {
const res = await fetchAPI(`
query {
photo (limit: 11, sort: ["-date_created"]) {
slug
title
city
location {
name
slug
country {
slug
name
flag { id }
}
}
image { id }
}
}
`)
const { data } = res
return {
body: {
photos: data.photo
}
}
} catch (error) {
return {
status: 404,
}
}
}