2021-12-02 20:13:08 +01:00
|
|
|
import { VercelRequest, VercelResponse } from '@vercel/node'
|
2021-12-03 01:40:34 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2021-12-02 20:13:08 +01:00
|
|
|
|
|
|
|
export default async (req: VercelRequest, res: VercelResponse) => {
|
|
|
|
if (!process.env.NOMADLIST_PROFILE) return
|
|
|
|
|
|
|
|
try {
|
2021-12-03 01:40:34 +01:00
|
|
|
const response: AxiosResponse<NomadListLocationResponse> = await axios(
|
2021-12-02 20:13:08 +01:00
|
|
|
`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)
|
|
|
|
}
|
|
|
|
}
|