From 1f3ba2bff10e0228bbf4c8163d48dd5fd6083f1f Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 23 Feb 2021 15:54:28 +0000 Subject: [PATCH] Allow origin to be overridden by query Specifying overrideOrigin in the URL now sets up the store with the modified origin. This is intended for development, and makes it much less annoying to develop with a Vue dev server. --- openflexure_microscope/api/static/src/store.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/openflexure_microscope/api/static/src/store.js b/openflexure_microscope/api/static/src/store.js index 8b92ca38..31f1fd0a 100644 --- a/openflexure_microscope/api/static/src/store.js +++ b/openflexure_microscope/api/static/src/store.js @@ -3,9 +3,22 @@ import Vuex from "vuex"; Vue.use(Vuex); +function getOriginFromLocation(){ + // This will default to the same origin that's serving + // the web app - but can be overridden by the URL. + // See also devTools.vue which can change the origin. + let url = new URL(window.location.href); + let origin = url.searchParams.get("overrideOrigin"); + if(origin){ + return origin; + }else{ + return url.origin; + } +} + export default new Vuex.Store({ state: { - origin: window.location.origin, + origin: getOriginFromLocation(), available: false, waiting: false, error: "",