Configuring Realm Object Server 🛠

When constructing a ROS instance, you can pass in configuration values simply through a JavaScript Object

const config = {
  featureUnlockToken: `YOUR_FEATURE_UNLOCK_TOKEN`,
  security: {
    privateKey: fs.readFile('./MY_PRIVATE_KEY.pkcs12') // or some string
    publicKey: fs.readFile('./MY_PUBLIC_KEY.pub') // or some string
  },
  syncWorkers: [
    `localhost:9822`,
    `localhost:9324`
  ]
  backup: {
    ...configsForHighAvailability
  }
  login: function(req, res, done) {
    myCustomlogin(req.body.username, req.body.password)
      .then(function(token) {
        done(token)
      })
      .catch(err => {
        done(err)
      })

  }
}

const ros = new ROS(config)
ros.listen(4500)

Here's an overview of some of the configuration values and what they do

  • featureUnlockToken - before known as the "accessToken". This is a string that we give to our Professional and Enterprise customers to unlock special features, like the Data Adapter, Global Notifier, and many more. We've decided that throwing words like "ADMINTOKEN" and "ACCESS_TOKEN" were simply too confusing

  • login: a function that gets fired when a client sends a JSON object. Your can choose to implement this by returning a token. You can read more about this in the Authentication section.

  • security: these are optional keys to help the server encrypt and sign requests coming in an out of your ROS instance. You can leave this undefined for development purposes

  • backup: this is an enterprise feature that allows you specify how to backup. It will be a list of other instances and or locations to save back up data.

  • port: this is either a string or number value with the port that you'd like ROS to start on. If you omit this we will use the default 9080 value. This is not compatible if you are binding your ros instance to an express route.

  • adminToken: this is either a string of your choice or a function of your choice that should return a string

Extending Realm Object Server with Services and Plugins

Your ROS instance is a fully equipped server that mimic's express' middleware API. Thus any service or plugin can easily be attached via the use method

For example our REST Api is a seperate module that you can install with npm install realm-object-server-rest-api --save.

In your index.js you can now attach our module easily like so:

const ROS = require('realm-object-server')
const ROSRest = require('realm-object-server-rest-api')
const ros = new ROS()

ros.use(new ROSRest({
    ...configsforRestApi
})
// or even bind a middleware service to path if the plugin supports this

ros.use(`/custompluginendpoint`, new ROSRest({
    ...configsforRestApi
})

ros.listen(9080)

results matching ""

    No results matching ""