location/api/index.ts

39 lines
963 B
TypeScript
Raw Normal View History

2024-02-06 00:00:14 +01:00
// import { getLastCheckin } from '../lib/foursquare'
import { NomadListLocation, getNomadList } from '../lib/nomadlist'
2021-12-02 20:13:08 +01:00
2022-11-17 15:36:16 +01:00
export const config = {
2024-02-04 23:03:22 +01:00
runtime: 'edge'
2022-11-17 15:36:16 +01:00
}
interface Location extends NomadListLocation {
lastCheckin?: string
}
declare type LocationResponse = {
now: Location
next: Location
2022-11-17 15:36:16 +01:00
}
2024-02-06 00:00:14 +01:00
export async function GET() {
2021-12-02 20:13:08 +01:00
try {
const nomadlist = await getNomadList()
2024-02-04 23:03:22 +01:00
// const foursquare = await getLastCheckin()
const foursquare = 'disabled'
2022-11-17 00:19:53 +01:00
const response = {
now: { ...nomadlist.now, ...(foursquare && { lastCheckin: foursquare }) },
next: { ...nomadlist.next }
} as LocationResponse
2021-12-02 20:13:08 +01:00
return new Response(JSON.stringify(response, null, 2), {
2024-02-06 00:00:14 +01:00
status: 200,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 's-maxage=300, stale-while-revalidate=300'
}
2022-11-17 15:36:16 +01:00
})
2021-12-02 20:13:08 +01:00
} catch (error) {
return new Response(JSON.stringify(error, null, 2), { status: 500 })
2021-12-02 20:13:08 +01:00
}
}