ClsiApp.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  6. * DS102: Remove unnecessary code created because of implicit returns
  7. * DS103: Rewrite code to no longer use __guard__
  8. * DS205: Consider reworking code to avoid use of IIFEs
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const app = require('../../../../app')
  13. require('@overleaf/logger').logger.level('info')
  14. const logger = require('@overleaf/logger')
  15. const Settings = require('@overleaf/settings')
  16. module.exports = {
  17. running: false,
  18. initing: false,
  19. callbacks: [],
  20. ensureRunning(callback) {
  21. if (callback == null) {
  22. callback = function () {}
  23. }
  24. if (this.running) {
  25. return callback()
  26. } else if (this.initing) {
  27. return this.callbacks.push(callback)
  28. } else {
  29. this.initing = true
  30. this.callbacks.push(callback)
  31. return app.listen(
  32. Settings.internal.clsi.port,
  33. Settings.internal.clsi.host,
  34. error => {
  35. if (error != null) {
  36. throw error
  37. }
  38. this.running = true
  39. logger.info('clsi running in dev mode')
  40. return (() => {
  41. const result = []
  42. for (callback of Array.from(this.callbacks)) {
  43. result.push(callback())
  44. }
  45. return result
  46. })()
  47. }
  48. )
  49. }
  50. },
  51. }