Skip to content

Commit

Permalink
Working around CORS issues with location aquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
jolzee committed Mar 25, 2020
1 parent 1c513dc commit 7cbe42c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ function storeSetup(vuetify) {
},
getters: {
locationInfo(state) {
return `&${generateQueryParams(state.locationInfo)}`;
let locationInfo = state.locationInfo;
return locationInfo ? `&${generateQueryParams(locationInfo)}` : "";
},
emergencyConfig(state) {
return state.ui.emergencyConfig;
Expand Down
12 changes: 10 additions & 2 deletions src/utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,15 @@ export default class Setup {
}, 2000);
if (window.leopardConfig.mustSendLocationAtLogin) {
superagent
.get("https://cors-anywhere.herokuapp.com/http://www.geoplugin.net/json.gp")
.accept("application/json")
.get("https://api.ipify.org")
.then(res => {
return superagent
.get(
"https://cors-anywhere.herokuapp.com/http://www.geoplugin.net/json.gp?ip=" +
res.text
)
.accept("application/json");
})
.then(res => {
const loc = JSON.parse(res.text);
logger.debug(`Location Information`, loc);
Expand All @@ -272,6 +279,7 @@ export default class Setup {
resolve(vuetify);
})
.catch(err => {
this.LOCATION = "";
logger.error(`Unable to obtain location info`, err);
resolve(vuetify);
});
Expand Down
32 changes: 19 additions & 13 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export function debounce(func, wait, immediate) {
* Smooth scroll
*/
// easing functions http://goo.gl/5HLl8
Math.easeInOutQuad = function(t, b, c, d) {
Math.easeInOutQuad = function (t, b, c, d) {
t /= d / 2;
if (t < 1) {
return (c / 2) * t * t + b;
Expand All @@ -326,24 +326,24 @@ Math.easeInOutQuad = function(t, b, c, d) {
return (-c / 2) * (t * (t - 2) - 1) + b;
};

Math.easeInCubic = function(t, b, c, d) {
Math.easeInCubic = function (t, b, c, d) {
const tc = (t /= d) * t * t;
return b + c * tc;
};

Math.inOutQuintic = function(t, b, c, d) {
Math.inOutQuintic = function (t, b, c, d) {
const ts = (t /= d) * t;
const tc = ts * t;
return b + c * (6 * tc * ts + -15 * ts * ts + 10 * tc);
};

// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
export const requestAnimFrame = (function() {
export const requestAnimFrame = (function () {
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
function (callback) {
window.setTimeout(callback, 1000 / 60);
}
);
Expand All @@ -368,7 +368,7 @@ export const scrollTo = (to, callback, duration) => {
let currentTime = 0;
const increment = 20;
duration = typeof duration === "undefined" ? 500 : duration;
const animateScroll = function() {
const animateScroll = function () {
// increment the time
currentTime += increment;
// find the value with the quadratic in-out easing function
Expand Down Expand Up @@ -606,7 +606,7 @@ export const unescapeHtml = str => {
* Escape string into unicode sequences
*/
export const escapeUnicode = (str, shouldEscapePrintable) => {
return str.replace(/[\s\S]/g, function(ch) {
return str.replace(/[\s\S]/g, function (ch) {
// skip printable ASCII chars if we should not escape them
if (!shouldEscapePrintable && /[\x20-\x7E]/.test(ch)) {
return ch;
Expand Down Expand Up @@ -834,7 +834,7 @@ export const download = (data, filename, type = "text/plain") => {
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
Expand Down Expand Up @@ -885,10 +885,16 @@ export const decodeHTML = html => {
return txt.value;
};

export const generateQueryParams = jsObject =>
Object.keys(jsObject)
.map(key => `${key}=${jsObject[key]}`)
.join("&");
export const generateQueryParams = jsObject => {
let returnVal = "";
if (jsObject) {
returnVal = Object.keys(jsObject)
.map(key => `${key}=${jsObject[key]}`)
.join("&");
}
console.log("RETURN VAL", returnVal);
return returnVal;
};

export const getParameterByName = (name, url) => {
if (!url) url = window.location.href;
Expand All @@ -911,7 +917,7 @@ export const makeSolutionUnique = solution => {

export const getUrlVarsAsObj = () => {
const vars = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
return vars;
Expand Down

0 comments on commit 7cbe42c

Please sign in to comment.