location/api/index.ts

34 lines
846 B
TypeScript
Raw Normal View History

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 = {
runtime: 'experimental-edge'
}
interface Location extends NomadListLocation {
lastCheckin?: string
}
declare type LocationResponse = {
now: Location
next: Location
2022-11-17 15:36:16 +01:00
}
export default async function handler() {
2021-12-02 20:13:08 +01:00
try {
const nomadlist = await getNomadList()
const foursquare = await getLastCheckin()
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), {
headers: { 'content-type': 'application/json' }
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
}
}