Initial commit
This commit is contained in:
50
test.js
Normal file
50
test.js
Normal file
@ -0,0 +1,50 @@
|
||||
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 Cawang–Pluit
|
||||
* 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('Cawang–Pluit'));
|
||||
console.log(typeof null);
|
||||
console.log(typeof encodeURIComponent(null));
|
||||
})();
|
||||
Reference in New Issue
Block a user