main.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. allow_origin = "*"
  20. )
  21. def get_command(self):
  22. """Get the command and kwargs to run.
  23. """
  24. # Run the node script with command arguments.
  25. config = dict(
  26. baseUrl='http://localhost:{}{}'.format(self.serverapp.port, self.settings['base_url']),
  27. token=self.settings['token'])
  28. with open(osp.join(HERE, 'config.json'), 'w') as fid:
  29. json.dump(config, fid)
  30. cmd = [which('node'),
  31. 'index.js', '--jupyter-config-data=./config.json']
  32. return cmd, dict(cwd=HERE)
  33. if __name__ == '__main__':
  34. NodeApp.launch_instance()