ClsiApp.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. __guard__(
  33. Settings.internal != null ? Settings.internal.clsi : undefined,
  34. x => x.port
  35. ),
  36. 'localhost',
  37. error => {
  38. if (error != null) {
  39. throw error
  40. }
  41. this.running = true
  42. logger.info('clsi running in dev mode')
  43. return (() => {
  44. const result = []
  45. for (callback of Array.from(this.callbacks)) {
  46. result.push(callback())
  47. }
  48. return result
  49. })()
  50. }
  51. )
  52. }
  53. },
  54. }
  55. function __guard__(value, transform) {
  56. return typeof value !== 'undefined' && value !== null
  57. ? transform(value)
  58. : undefined
  59. }