text: import path from "path"
  import config from "app/config"
  
  export function addConnection(server, labels) {
    const appId = labels[0]
    const options = config[appId]
    if (options) {
      server.connection({
        labels,
        host: config.server.host,
        port: config.server.port + options.portIndex
      })
    }
  }
  
  export function handleError(error) {
    if (error) {
      throw error
    }
  }
  
  export function loadApps(server) {
    server.connections.forEach(connection => {
      const appId = connection.settings.labels[0]
      const options = config[appId]
      if (options && options.module) {
        const appPath = options.module.indexOf("/") === -1 ? options.module : path.resolve(options.module)
        server.select(appId).register({
          register: require(appPath),
          options
        }, handleError)
      }
    })
  }
  