Horizon: Add `.hz/server.js` for configuring the server programatically

Created on 12 May 2016  路  1Comment  路  Source: rethinkdb/horizon

I'm starting to think it might be nice to have a file like .hz/server.js where you can programmatically interact with the Horizon server before it's launched. This would be run and work both locally and when deployed to Horizon Cloud. I think this has a couple advantages:

  1. Provides a mechanism for both self-host and non-self-host users to interact with and extend the server.

    • Currently only self-host users are able to extend the server in this way.

    • Makes it easier/possible for non-self-host users to use third-party plugins or extensions that may become available.

  2. A programmatic API is inherently more powerful than configuration files. There may be many cases now and in the future where programmatic APIs allow you to do things that would be impossible to represent in config files.

    • Examples: custom commands from #337 (comment), custom validation logic, etc

    • Read in configuration from arbitrary sources, apply config dynamically based on environment, etc.

  3. Faster prototyping and delivery of new features without having to worry about config formats.

    • If something is too difficult to define in a config file we can still expose an API for it that everyone can use.

    • The server can implement and users can benefit from new features before we decide how to represent it in the config files.

The way this might work is that your .hz/server.js would export a single function that takes the Horizon server instance and lets you do whatever you want with it. After the server is started and any default configuration is applied, this file gets required and passed the Horizon server instance:

// .hz/server.js

module.exports = function (Horizon) {
  Horizon.command('custom', (params) => {
    // custom command implementation
  })
}
server still formulating

Most helpful comment

This seems like a reasonable idea. There is definitely a point where too many config options is way worse than just providing a nice javascript interface.

>All comments

This seems like a reasonable idea. There is definitely a point where too many config options is way worse than just providing a nice javascript interface.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josephg picture josephg  路  6Comments

deontologician picture deontologician  路  3Comments

marshall007 picture marshall007  路  8Comments

arthurvi picture arthurvi  路  4Comments

coffeemug picture coffeemug  路  4Comments