DocstoreApp.js 1.5 KB

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