From 74734113b02f2875e159bc561653911fa2ae27f3 Mon Sep 17 00:00:00 2001 From: choelzl Date: Fri, 16 Jul 2021 12:17:32 +0200 Subject: [PATCH] cleanup --- public/js/main.js | 11 ++--------- router/api.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index ccd2a56..4e134d2 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -9,19 +9,12 @@ const gen_id = (length)=>{ } const query_nominatim = (q,f)=>{ - const ENDPOINT = 'https://nominatim.openstreetmap.org/'; - const FORMAT = 'jsonv2'; - return axios.get(ENDPOINT, { - params: { - format: FORMAT, - q:q, - }, - }).then(res=>res.data).then(res=>res.filter(f)); + const ENDPOINT = '/api/place/'+q; + return axios.get(ENDPOINT).then(res=>res.data).then(res=>res.filter(f)); } const query_flight = (q)=>{ const ENDPOINT = '/api/flight/'+q; - const FORMAT = '-'; return axios.get(ENDPOINT).then(res=>res.data); } diff --git a/router/api.js b/router/api.js index 5dd6277..7c79f21 100644 --- a/router/api.js +++ b/router/api.js @@ -12,7 +12,21 @@ module.exports = (fastify, opts, done) => { limit:16, type: 'schedule' } - }).then(res=>{reply.send(res.data)}); + }).then(res=>reply.send(res.data)); + }else{ + reply.send([]); + } + }); + fastify.get('/place/:id', async (req,reply) => { + const ENDPOINT = 'https://nominatim.openstreetmap.org/'; + const FORMAT = 'jsonv2'; + if(req.params.id){ + axios.get(ENDPOINT,{ + params: { + format: FORMAT, + q: req.params.id, + } + }).then(res=>reply.send(res.data)); }else{ reply.send([]); }