DocstoreApp.js 670 B

123456789101112131415161718192021222324252627
  1. const app = require('../../../../app')
  2. require('@overleaf/logger').logger.level('error')
  3. const settings = require('@overleaf/settings')
  4. module.exports = {
  5. running: false,
  6. initing: false,
  7. callbacks: [],
  8. ensureRunning(callback) {
  9. if (this.running) {
  10. return callback()
  11. } else if (this.initing) {
  12. return this.callbacks.push(callback)
  13. }
  14. this.initing = true
  15. this.callbacks.push(callback)
  16. app.listen(settings.internal.docstore.port, '127.0.0.1', error => {
  17. if (error != null) {
  18. throw error
  19. }
  20. this.running = true
  21. for (callback of Array.from(this.callbacks)) {
  22. callback()
  23. }
  24. })
  25. },
  26. }