@linev , I am creating a web application which will render a .root file in client application, when the user chooses to open the file. For this I have to use JSROOT. The server is written in golang. How can I send request to JSROOT from server, to read a local file and send the response which will then be rendered on client side.
I tried to create a golang FileServer and use JSROOT to read a remote file, but it doesn’t seem to work.
Please suggest how I can achieve this?
In principal, you could avoid CORS problem by installing JSROOT on your server and using it like: http://your_server/jsroot/?file=http://your_server/files/abc.root&item=...
Last your question - how to trigger reading and drawing from the server?
Here you need to implement some HTML/JavaScript code yourself.
In this code your should request server when data is there - this is fully application-specific.
Once data can be displayed, just use small JSROOT-based code to load and displayed data as described here: https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#file-api
Thanks @linev The first solution works. I created a file server. I tried that before as well but I was not specifying the item parameter in url earlier, that’s why nothing was showing up.
Regards,
Mohit
@linev I face another problem using this. I have a golang web service which is hosted at something like http://localhost:9998/open/file.root. In the service code I make an http request to jsroot using http.Get as follows: resp, err := http.Get("https://root.cern/js/latest/?file=http://localhost:8100/file.root&item=c1;1"). http://localhost:8100 is the location of file server.So I use the filename provided in the first url (the service endpoint) and make a get request to jsroot.
When I navigate to the url: https://root.cern/js/latest/?file=http://localhost:8100/file.root&item=c1;1 in the browser, it loads the file. But when I make a request in golang as above it doesn’t load. When I looked in the network console, the jsroot application redirects to different urls which uses the same origin and path as the one in browser (the service endpoint) and not the one in get request. So, in my case the following are the redirected urls: http://localhost:9998/open/scripts/JSRootCore.min.js?gui
and similar. When I navigate to the same url in browser the corresponding url is https://root.cern/js/latest/scripts/JSRootCore.min.js?gui
The origin is the one in browser and not the code.
How do I get around with this?
Thanks,
Mohit
Hi, Please suggest other ideas. I need to create a service that returns the response to be loaded on the client side, which is to read a root file. Is it not possible without installing jsroot on the server?
Hi @linev , one more thing. What if the remote file server uses authentication for allowing to read the file. How can jsroot send authentication token along with the request to open file?
Up to now there is not special functionality in JSROOT to handle authentication - there are too many different methods. If you do have special requirement, probably one can add extra feature to JSROOT.