Install JsRoot on a Nginx server

[1] Set up a nginx web server. Check your URL shows a test page.

[2] Download the jsroot package “JsRootXXX.tar.gz” provided from
https://github.com/linev/jsroot/blob/master/docs/JSROOT.md

[3] Unpack it in your server e.g. /var/somewhere. The files in the package would not work out of the box. You may need to modify index.htm and put some root files in “files” directory to test. If you don’t have your own root file to test, hsimple.root can be found https://root.cern/js/files/hsimple.root

[4] Modify nginx root path or put the jsroot package in a proper path.

vi /etc/nginx/nginx.conf

server {
listen 80;
listen [::]:80;
server_name _;
root /path/to/jsroot; # the location including index.html, modules, etc.

Or you may put the jsroot package in nginx root location.

[5] Because some modules have “.mjs” extension not “.js”, you may get an error like:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

Then you tell nginx the type “.mjs”:
sudo vi /etc/nginx/mime.types
Modify the following line: js => js mjs:
application/javascript js mjs;
Reload nginx:
sudo nginx -s reload
And you might want to clear your browser cache.

[6] Modify the provided example html file. The index.html may be like below (I have rewritten only <div id =”simpleGUI” path=”./files/” files=”hsimple.root”>)

<html lang="en">
<head>
<meta charset="utf-8">
<title>Read a ROOT file</title>
<link rel="shortcut icon" href="img/RootIcon.ico"/>
</head>
<body>
<div id="simpleGUI" path="./files/" files="hsimple.root">
loading scripts ...
</div>
<script type="module">
import { buildGUI } from './modules/gui.mjs';
buildGUI("simpleGUI");
</script>
</body>
</html>

[7] Access your URL and load hsimple.root.

JSRoot.core.js は使わなくなったのかな?いまはmodules 以下の mjs ファイルをimport するようになっているようだ.


カテゴリー: 未分類 パーマリンク