Skip to content
Snippets Groups Projects
Commit 00970c5f authored by Markin Igor's avatar Markin Igor
Browse files

Rework host.

parent 9145a129
No related branches found
No related tags found
1 merge request!4Use webpack for bundling JS libs and move Golang code related to Iframe generation there
...@@ -10,7 +10,9 @@ WopiAPI.prototype.getPassports = function(publicKey, uuid, token, fileID) { ...@@ -10,7 +10,9 @@ WopiAPI.prototype.getPassports = function(publicKey, uuid, token, fileID) {
} }
}; };
return axios.post('{{host}}:{{port}}/getPassports', {}, requestConfig); const urlParts = window.API_HOST.split(':');
return axios.post(urlParts[0] + urlParts[1] + ':8787/getPassports', {}, requestConfig);
}; };
wopiAPI = new WopiAPI(); wopiAPI = new WopiAPI();
...@@ -32,6 +32,7 @@ func GetClientJsLibrary(iframeUrl string) string { ...@@ -32,6 +32,7 @@ func GetClientJsLibrary(iframeUrl string) string {
func GetIframeJsLibrary(host string, func GetIframeJsLibrary(host string,
endPoints map[string]*types.EndPoint) string { endPoints map[string]*types.EndPoint) string {
result := "<script>\n\n" result := "<script>\n\n"
result += "window.API_HOST = '" + host + "';\n\n"
var keys []string var keys []string
for k := range endPoints { for k := range endPoints {
...@@ -48,7 +49,7 @@ func GetIframeJsLibrary(host string, ...@@ -48,7 +49,7 @@ func GetIframeJsLibrary(host string,
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
methods := generatePenpalRemoteMethods(host, endPoints) methods := generatePenpalRemoteMethods(endPoints)
methods += getWopiAPIPenpalMethods() methods += getWopiAPIPenpalMethods()
viamApi := strings.Replace(string(dat), "placeholderForExternalMethods:1", methods, 1) viamApi := strings.Replace(string(dat), "placeholderForExternalMethods:1", methods, 1)
...@@ -59,7 +60,13 @@ func GetIframeJsLibrary(host string, ...@@ -59,7 +60,13 @@ func GetIframeJsLibrary(host string,
result += viamApi + "\n\n" result += viamApi + "\n\n"
result += getWopiAPI(host) dat, err = ioutil.ReadFile("../vcl/javascript/dist/wopiapi-iframe.js")
if err != nil {
fmt.Println(err.Error())
}
result += string(dat) + "\n\n"
result += "\n\nfunction ViamAPI() {\n" + result += "\n\nfunction ViamAPI() {\n" +
" this.config = {\n" + " this.config = {\n" +
...@@ -118,7 +125,7 @@ func GetIframeJsLibrary(host string, ...@@ -118,7 +125,7 @@ func GetIframeJsLibrary(host string,
} }
result += "ViamAPI.prototype." + packageStr + strings.Title(methodStr) + " = function(" + args + ") {\n" + result += "ViamAPI.prototype." + packageStr + strings.Title(methodStr) + " = function(" + args + ") {\n" +
" return axios.post('" + host + packageStr + "/" + methodStr + "', {\n" " return axios.post(window.API_HOST + '" + packageStr + "/" + methodStr + "', {\n"
for i := 0; i < lenFields; i++ { for i := 0; i < lenFields; i++ {
result += " " + fields[i].name + ": " + fields[i].name + "Arg" result += " " + fields[i].name + ": " + fields[i].name + "Arg"
...@@ -143,7 +150,7 @@ func GetIframeJsLibrary(host string, ...@@ -143,7 +150,7 @@ func GetIframeJsLibrary(host string,
methodStr := splits[len(splits)-1] methodStr := splits[len(splits)-1]
result += "ViamAPI.prototype." + packageStr + strings.Title(methodStr) + " = function() {\n" + result += "ViamAPI.prototype." + packageStr + strings.Title(methodStr) + " = function() {\n" +
" return axios.post('" + host + "/" + packageStr + "/" + methodStr + "', {}, this.config);\n" + " return axios.post(window.API_HOST + '" + packageStr + "/" + methodStr + "', {}, this.config);\n" +
"}\n\n" "}\n\n"
} }
} }
...@@ -563,8 +570,7 @@ func dominantField(fields []field) (field, bool) { ...@@ -563,8 +570,7 @@ func dominantField(fields []field) (field, bool) {
return fields[0], true return fields[0], true
} }
func generatePenpalRemoteMethods(host string, func generatePenpalRemoteMethods(endPoints map[string]*types.EndPoint) string {
endPoints map[string]*types.EndPoint) string {
var keys []string var keys []string
for k := range endPoints { for k := range endPoints {
keys = append(keys, k) keys = append(keys, k)
...@@ -780,18 +786,3 @@ func getWopiAPIPenpalMethods() string { ...@@ -780,18 +786,3 @@ func getWopiAPIPenpalMethods() string {
}); });
}` }`
} }
func getWopiAPI(url string) string {
dat, err := ioutil.ReadFile("../vcl/javascript/dist/wopiapi-iframe.js")
if err != nil {
fmt.Println(err.Error())
}
urlParts := strings.Split(url, ":")
wopiAPI := strings.Replace(string(dat), "{{host}}", urlParts[0]+":"+urlParts[1], -1)
wopiAPI = strings.Replace(wopiAPI, "{{port}}", "8787", -1)
wopiAPI += "\n\n"
return wopiAPI
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment