cross.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. const { Service } = require("ee-core");
  3. const Cross = require("ee-core/cross");
  4. const Log = require("ee-core/log");
  5. const Ps = require("ee-core/ps");
  6. const path = require("path");
  7. const Is = require("ee-core/utils/is");
  8. /**
  9. * cross(service层为单例)
  10. * @class
  11. */
  12. class CrossService extends Service {
  13. constructor(ctx) {
  14. super(ctx);
  15. }
  16. /**
  17. * create python service
  18. * In the default configuration, services can be started with applications.
  19. * Developers can turn off the configuration and create it manually.
  20. */
  21. async createPythonServer() {
  22. // method 1: Use the default Settings
  23. //const entity = await Cross.run(serviceName);
  24. // method 2: Use custom configuration
  25. const serviceName = "python";
  26. const opt = {
  27. name: "pyapp",
  28. cmd: path.join(Ps.getExtraResourcesDir(), "py", "pyapp"),
  29. directory: path.join(Ps.getExtraResourcesDir(), "py"),
  30. args: ["--port=7074"],
  31. windowsExtname: true,
  32. appExit: true,
  33. };
  34. const entity = await Cross.run(serviceName, opt);
  35. Log.info("server name:", entity.name);
  36. Log.info("server config:", entity.config);
  37. Log.info("server url:", entity.getUrl());
  38. return;
  39. }
  40. }
  41. CrossService.toString = () => "[class CrossService]";
  42. module.exports = CrossService;