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
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
......@@ -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();
......@@ -32,6 +32,7 @@ func GetClientJsLibrary(iframeUrl string) string {
func GetIframeJsLibrary(host string,
endPoints map[string]*types.EndPoint) string {
result := "<script>\n\n"
result += "window.API_HOST = '" + host + "';\n\n"
var keys []string
for k := range endPoints {
......@@ -48,7 +49,7 @@ func GetIframeJsLibrary(host string,
fmt.Println(err.Error())
}
methods := generatePenpalRemoteMethods(host, endPoints)
methods := generatePenpalRemoteMethods(endPoints)
methods += getWopiAPIPenpalMethods()
viamApi := strings.Replace(string(dat), "placeholderForExternalMethods:1", methods, 1)
......@@ -59,7 +60,13 @@ func GetIframeJsLibrary(host string,
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" +
" this.config = {\n" +
......@@ -118,7 +125,7 @@ func GetIframeJsLibrary(host string,
}
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++ {
result += " " + fields[i].name + ": " + fields[i].name + "Arg"
......@@ -143,7 +150,7 @@ func GetIframeJsLibrary(host string,
methodStr := splits[len(splits)-1]
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"
}
}
......@@ -563,8 +570,7 @@ func dominantField(fields []field) (field, bool) {
return fields[0], true
}
func generatePenpalRemoteMethods(host string,
endPoints map[string]*types.EndPoint) string {
func generatePenpalRemoteMethods(endPoints map[string]*types.EndPoint) string {
var keys []string
for k := range endPoints {
keys = append(keys, k)
......@@ -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