This commit is contained in:
126
router/api.js
126
router/api.js
@ -1,68 +1,72 @@
|
||||
const axios = require('axios');
|
||||
const axios = require("axios");
|
||||
|
||||
module.exports = (fastify, opts, done) => {
|
||||
fastify.get('/flight/:id', async (req,reply) => {
|
||||
const ENDPOINT = 'https://www.flightradar24.com/v1/search/web/find';
|
||||
const FORMAT = '-';
|
||||
if(req.params.id){
|
||||
axios.get(ENDPOINT,{
|
||||
params: {
|
||||
format: FORMAT,
|
||||
query: req.params.id,
|
||||
limit:16,
|
||||
type: 'schedule'
|
||||
}
|
||||
}).then(res=>reply.send(res.data));
|
||||
}else{
|
||||
return reply.send([]);
|
||||
}
|
||||
return reply
|
||||
});
|
||||
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{
|
||||
return reply.send([]);
|
||||
}
|
||||
return reply;
|
||||
});
|
||||
fastify.get("/flight/:id", async (req, reply) => {
|
||||
const ENDPOINT = "https://www.flightradar24.com/v1/search/web/find";
|
||||
const FORMAT = "-";
|
||||
if (req.params.id) {
|
||||
axios
|
||||
.get(ENDPOINT, {
|
||||
params: {
|
||||
format: FORMAT,
|
||||
query: req.params.id,
|
||||
limit: 16,
|
||||
type: "schedule",
|
||||
},
|
||||
})
|
||||
.then((res) => reply.send(res.data));
|
||||
} else {
|
||||
return reply.send([]);
|
||||
}
|
||||
return reply;
|
||||
});
|
||||
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 {
|
||||
return reply.send([]);
|
||||
}
|
||||
return reply;
|
||||
});
|
||||
|
||||
fastify.get('/:id', async (req, reply) => {
|
||||
if(req.params.id == undefined)
|
||||
return reply.code(400).send({error:"No ID query parameter"});
|
||||
fastify.get("/:id", async (req, reply) => {
|
||||
if (req.params.id == undefined)
|
||||
return reply.code(400).send({ error: "No ID query parameter" });
|
||||
|
||||
fastify.level.db.get(req.params.id, (err, val) => {
|
||||
if(err){
|
||||
console.warn(err);
|
||||
reply.code(500).send();
|
||||
} else {
|
||||
reply.send(JSON.parse(val));
|
||||
}
|
||||
});
|
||||
return reply
|
||||
});
|
||||
fastify.level.db.get(req.params.id, (err, val) => {
|
||||
if (err) {
|
||||
console.warn(err);
|
||||
reply.code(500).send();
|
||||
} else {
|
||||
reply.send(JSON.parse(val));
|
||||
}
|
||||
});
|
||||
return reply;
|
||||
});
|
||||
|
||||
fastify.post('/:id', async (req, reply) => {
|
||||
if(req.params.id == undefined)
|
||||
return reply.code(400).send({error:"No ID query parameter"});
|
||||
fastify.post("/:id", async (req, reply) => {
|
||||
if (req.params.id == undefined)
|
||||
return reply.code(400).send({ error: "No ID query parameter" });
|
||||
|
||||
fastify.level.db.put(req.params.id, JSON.stringify(req.body), (err) => {
|
||||
if(err){
|
||||
console.warn(err);
|
||||
reply.code(500).send({error:"Error with DB"});
|
||||
} else {
|
||||
reply.send({content:"ok"});
|
||||
}
|
||||
});
|
||||
return reply
|
||||
});
|
||||
fastify.level.db.put(req.params.id, JSON.stringify(req.body), (err) => {
|
||||
if (err) {
|
||||
console.warn(err);
|
||||
reply.code(500).send({ error: "Error with DB" });
|
||||
} else {
|
||||
reply.send({ content: "ok" });
|
||||
}
|
||||
});
|
||||
return reply;
|
||||
});
|
||||
|
||||
done();
|
||||
};
|
||||
done();
|
||||
};
|
||||
|
Reference in New Issue
Block a user