mirror of
https://github.com/kremalicious/location.git
synced 2024-11-22 09:56:59 +01:00
40 lines
968 B
TypeScript
40 lines
968 B
TypeScript
import { VercelRequest, VercelResponse } from '@vercel/node'
|
|
import axios, { AxiosResponse } from 'axios'
|
|
|
|
interface NomadListLocation {
|
|
city: string
|
|
country: string
|
|
country_code: string
|
|
latitude: number
|
|
longitude: number
|
|
epoch_start: number
|
|
epoch_end: number
|
|
date_start: string
|
|
date_end: string
|
|
place_photo: string
|
|
}
|
|
|
|
interface NomadListLocationResponse {
|
|
location: {
|
|
now: NomadListLocation
|
|
previous: NomadListLocation
|
|
next: NomadListLocation
|
|
}
|
|
}
|
|
|
|
export default async (req: VercelRequest, res: VercelResponse) => {
|
|
if (!process.env.NOMADLIST_PROFILE) return
|
|
|
|
try {
|
|
const response: AxiosResponse<NomadListLocationResponse> = await axios(
|
|
`https://nomadlist.com/@${process.env.NOMADLIST_PROFILE}.json?key=${process.env.NOMADLIST_KEY}`
|
|
)
|
|
if (!response?.data) return
|
|
|
|
// return only the location part of the data
|
|
res.json(response.data.location)
|
|
} catch (error) {
|
|
res.status(500).send(error)
|
|
}
|
|
}
|