Multiple Parse Initialize
Asked Answered
F

1

6

I have 2 apps on Parse. The first one is for production and the other one is for testing. In my back-office, I need to see the data from these 2 apps, but Parse.initialize() is a singleton, so I tried this:

(function (Prod) {
  Prod.initialize('APP_KEY', 'JAVASCRIPT_KEY');

  /**
   * My Code
   */
})(Object.create(Parse));

(function (Testing) {
  Testing.initialize('ANOTHER_APP_KEY', 'ANOTHER_JAVASCRIPT_KEY');

  /**
   * My Other Code
   */
})(Object.create(Parse));

And of course, it didn't worked. Any advice ?

EDIT: It seems that the app keys are saved to the local storage. It prevent the usage of 2 instances of Parse ...

Fetal answered 2/6, 2015 at 15:35 Comment(1)
have you found out the solutionGilead
U
0

I came up with this initializeMulti-function which seems to do the job:

  var Parse = require('parse/node')

  Parse.initializeMulti = (appId, javascriptKey, masterKey) => {
      Object.keys(require.cache).forEach(function(key) { delete require.cache[key] })
      var _Parse = require('parse/node')
      _Parse.initialize( appId, javascriptKey, masterKey )
      return _Parse
  }

  Parse.foo = Parse.initializeMulti('foo','foo','foo')
  Parse.foo.serverURL = 'http://localhost/foo'

  Parse.bar = Parse.initializeMulti('bar','bar','bar')
  Parse.bar.serverURL = 'http://localhost/bar'

  console.dir( Parse.foo.CoreManager.get('APPLICATION_ID') )   // foo
  console.dir( Parse.bar.CoreManager.get('APPLICATION_ID') )   // bar

Unstrap answered 19/6, 2020 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.