main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. from __future__ import print_function, absolute_import
  4. import json
  5. import os.path as osp
  6. from jupyterlab_server.process import which
  7. from jupyterlab_server.process_app import ProcessApp
  8. HERE = osp.dirname(osp.realpath(__file__))
  9. def _jupyter_server_extension_points():
  10. return [
  11. {
  12. 'module': __name__,
  13. 'app': NodeApp
  14. }
  15. ]
  16. class NodeApp(ProcessApp):
  17. name = __name__
  18. serverapp_config = dict(
  19. disable_check_xsrf = True,
  20. allow_origin = "*",
  21. token=""
  22. )
  23. def get_command(self):
  24. """Get the command and kwargs to run.
  25. """
  26. # Run the node script with command arguments.
  27. config = dict(
  28. baseUrl='http://localhost:{}{}'.format(self.serverapp.port, self.settings['base_url']),
  29. token="")
  30. with open(osp.join(HERE, 'config.json'), 'w') as fid:
  31. json.dump(config, fid)
  32. cmd = [which('node'),
  33. 'index.js', '--jupyter-config-data=./config.json']
  34. return cmd, dict(cwd=HERE)
  35. if __name__ == '__main__':
  36. NodeApp.launch_instance()