DocstoreApp.js 620 B

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