diff --git a/README.md b/README.md index d8fc497a8ef47b7436ad31560bbb904704c07348..f0d05293ba584e84ad8a42d7ca6ce979677c6f29 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,10 @@ const iframeUrl = "https://test.org/iframe"; // API url used to access endpoints const apiUrl = "https://test.org/api"; + +const wopiUrl = "https://test.org/wopi"; -this.library = setupViamAPI(containerId, methods, iframeUrl, apiUrl); +this.library = setupViamAPI(containerId, methods, iframeUrl, apiUrl, wopiUrl); this.library.then(lib => { this.listenerUUID = this.addListener({ diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 99cb8de5a12b5155158ab9f7da8e892914312a0e..e0bad330ad21eca36fad875c931f0cee3cc79935 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1571,8 +1571,9 @@ function getCertificateForPassport(passportUUID, internal) { const connection = Penpal.connectToParent({ // Methods child is exposing to parent methods: { - initializeApiHost: (apiUrl) => { + initialize: (apiUrl, wopiUrl) => { window.API_HOST = apiUrl.charAt(apiUrl.length - 1) === "/" ? apiUrl : apiUrl + "/"; + window.WOPI_URL = `${wopiUrl.charAt(wopiUrl.length - 1) === "/" ? wopiUrl : wopiUrl + "/"}getPassports`; }, createIdentity(pinCode) { return new Penpal.Promise(result => { diff --git a/javascript/src/iframe/wopiapi-iframe.js b/javascript/src/iframe/wopiapi-iframe.js index aefb502142b2209ff24a0aae9f3eaef1031a6fe0..7b9ac1bf6ad6b0f6afc3e815ed10681130c0ef06 100644 --- a/javascript/src/iframe/wopiapi-iframe.js +++ b/javascript/src/iframe/wopiapi-iframe.js @@ -3,14 +3,8 @@ const axios = require('axios'); function WopiAPI() {} WopiAPI.prototype.getPassports = function (fileID) { - const [protocol, host] = window.API_HOST.split(':'); - let url = `${protocol}:${host}${window.WOPI_URI_PREFIX}`; - - url = url.charAt(url.length - 1) === "/" ? url : url + "/"; - url += 'getPassports'; - const requestConfig = { - url, + url: window.WOPI_URL, method: 'POST', headers: { publicKey: window.viamApi.getConfig().headers.publicKey, diff --git a/javascript/src/viamapi-client.js b/javascript/src/viamapi-client.js index 96026f20b6506d72a5c6423b97e87586a6798481..7cea9b187c3b4c31fee36445255d35a66ea807bc 100644 --- a/javascript/src/viamapi-client.js +++ b/javascript/src/viamapi-client.js @@ -6,14 +6,20 @@ const Penpal = require('penpal').default; * @param methods - list of methods to be used in iframe * @param iframeUrl - iframe URL to connect * @param apiUrl - API URL used to access API endpoints + * @param wopiUrl - WOPI URL used to acces WopiAPI * @returns {*} */ -function setupViamAPI(divId, methods, iframeUrl, apiUrl) { +function setupViamAPI(divId, methods, iframeUrl, apiUrl, wopiUrl) { if (!apiUrl) { apiUrl = `${window.location.origin}/api/`; console.warn(`API host URL not specified. Fall back to ${apiUrl}`); // eslint-disable-line no-console } + if (!wopiUrl) { + wopiUrl = `${window.location.origin}/wopi/`; + console.warn(`WOPI host URL not specified. Fall back to ${wopiUrl}`); // eslint-disable-line no-console + } + if (!iframeUrl) { iframeUrl = `${window.location.origin}/vcl/js/iframe`; console.warn(`Iframe URL not specified. Fall back to ${iframeUrl}`); // eslint-disable-line no-console @@ -29,7 +35,7 @@ function setupViamAPI(divId, methods, iframeUrl, apiUrl) { }); return connection.promise - .then((child) => child.initializeApiHost(apiUrl).then(() => child)); + .then((child) => child.initialize(apiUrl, wopiUrl).then(() => child)); } window.setupViamAPI = setupViamAPI; diff --git a/main.go b/main.go index cc9cd0802f88ab2b59a16d44163e13966f40afd5..09618e9b28fb5810bf1e1470bbd25ec01cee124e 100644 --- a/main.go +++ b/main.go @@ -56,8 +56,7 @@ func buildViamAPI() string { prefixes := []string{} endPoints := server.GetEndPoints(prefixes) - result := "const axios = require('axios');\n" + - "window.WOPI_URI_PREFIX=\"" + server.GetWopiURIPrefix() + "\";\n\n" + result := "const axios = require('axios');\n" var keys []string for k := range endPoints {