Files
gps-backend/test.js
2025-05-29 08:59:40 +00:00

50 lines
1.6 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const axios = require('axios').default;
const url = require('url');
const request = require('./config/request');
// const makeRequest = require('request');
// using axios
(async () => {
let params = new url.URLSearchParams({
lat: -6.70982,
lon: 106.99451555555557,
format: 'geojson',
});
const axInstance = axios.create();
axios.defaults.timeout = 3000;
axios.defaults.crossDomain = true;
// respReverseGeo = await axios({
// url: request.osm_reverse_geo.urlFull,
// method: request.osm_reverse_geo.method,
// params: params,
// timeout: 3000,
// responseType: 'json',
// });
console.log('RUNNING');
let respReverseGeo = await axInstance.get(request.osm_reverse_geo.urlFull + '?' + params.toString(), {
timeout: 3000,
});
console.log(respReverseGeo.data);
console.log('SUCCESS');
});
// using standard http library
(async () => {
makeRequest('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
console.log(body.url);
console.log(body.explanation);
});
});
(async () => {
/**
* fix DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains
* because of string CawangPluit
* solution: https://stackoverflow.com/questions/23223718/failed-to-execute-btoa-on-window-the-string-to-be-encoded-contains-characte
* window.btoa( unescape(encodeURIComponent(str) ) is deprecated => window.btoa(encodeURIComponent(str))
*/
console.log(encodeURIComponent('CawangPluit'));
console.log(typeof null);
console.log(typeof encodeURIComponent(null));
})();