hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

Cannot register plugins in manifest registrations #61

Closed franzip closed 8 years ago

franzip commented 8 years ago

I am using this boilerplate for a project.

This is the error I get when I run npm start:

/Users/franzip/Work/project-api/node_modules/hapi/node_modules/hoek/lib/index.js:732
    throw new Error(msgs.join(' ') || 'Unknown error');
    ^

Error: Invalid register options {
  "data" [1]: {
    "dir": "/Users/franzip/Work/project-api/lib",
    "pattern": "fixtures.js"
  },
  "models" [2]: "/Users/franzip/Work/project-api/lib/models",
  "adapters" [3]: {
    "sails-mongo": {
      "pkFormat": "string",
      "syncable": true,
      "defaults": {
        "host": "localhost",
        "database": "sails",
        "port": 27017,
        "user": null,
        "password": null,
        "schema": false,
        "url": null,
        "w": 1,
        "wtimeout": 0,
        "fsync": false,
        "journal": false,
        "readPreference": null,
        "nativeParser": false,
        "forceServerObjectId": false,
        "recordQueryStats": false,
        "retryMiliSeconds": 5000,
        "numberOfRetries": 5,
        "ssl": false,
        "poolSize": 5,
        "socketOptions": {
          "noDelay": true,
          "keepAlive": 0,
          "connectTimeoutMS": 0,
          "socketTimeoutMS": 0
        },
        "auto_reconnect": true,
        "disableDriverBSONSizeCheck": false,
        "reconnectInterval": 200,
        "wlNext": {
          "caseSensitive": false
        }
      },
      "mongo": {},
      "identity": "sails-mongo"
    }
  },
  "connections" [4]: {
    "mydb": {
      "adapter": "sails-mongo",
      "host": "localhost",
      "port": 27017,
      "database": "mydb"
    }
  }
}

[1] "connections" is not allowed
[2] "adapters" is not allowed
[3] "models" is not allowed
[4] "data" is not allowed
    at Object.exports.contain.exports.reachTemplate.exports.assert.condition [as assert] (/Users/franzip/Work/project-api/node_modules/hapi/node_modules/hoek/lib/index.js:732:11)
    at Object.exports.apply (/Users/franzip/Work/project-api/node_modules/hapi/lib/schema.js:17:10)
    at module.exports.internals.Plugin.internals.Plugin.register.each [as register] (/Users/franzip/Work/project-api/node_modules/hapi/lib/plugin.js:180:22)
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:119:24
    at iterate (/Users/franzip/Work/project-apinode_modules/glue/node_modules/items/lib/index.js:36:13)
    at Object.exports.serial (/Users/franzip/Work/project-api/node_modules/glue/node_modules/items/lib/index.js:39:9)
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:117:19
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:129:9
    at iterate (/Users/franzip/Work/project-api/node_modules/glue/node_modules/items/lib/index.js:36:13)
    at done (/Users/franzip/Work/project-api/node_modules/glue/node_modules/items/lib/index.js:28:25)
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:101:13
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:129:9
    at iterate (/Users/franzip/Work/project-api/node_modules/glue/node_modules/items/lib/index.js:36:13)
    at done (/Users/franzip/Work/project-api/node_modules/glue/node_modules/items/lib/index.js:28:25)
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:92:9
    at /Users/franzip/Work/project-api/node_modules/glue/lib/index.js:129:9

I have updated most of the dependencies and this is my package.json:

"dependencies": {
    "bassmaster": "1.9.x",
    "bedwetter": "1.8.x",
    "boom": "3.1.x",
    "dogwater": "1.1.x",
    "glue": "3.1.x",
    "hapi": "12.x.x",
    "hapi-swagger": "3.3.x",
    "hoek": "3.x.x",
    "inert": "3.2.x",
    "joi": "7.2.x",
    "poop": "2.x.x",
    "vision": "4.x.x",
    "sails-mongo": "0.12.x"
  }

My manifest object looks like this (in /server.js):

var config = require('./config');
...
manifest: {
  server: {
  ...
  }, 
  connections: {
  ...
  },
  registrations: {
    {
      plugin: 'dogwater',
      options: config.dogwater
    },
    {
      plugin: 'poop',
      options: config.poop
    }
  }
}

This is /config.js:

module.exports = {
   ...
  dogwater: {
    connections: {
      mydb: {
        adapter: 'sails-mongo',
        host: 'localhost',
        port: 27017,
        database: 'mydb'
      }
    },
    adapters: {
      'sails-mongo': require('sails-mongo')
    },
    models: path.normalize(__dirname + '/lib/models'),
    data: {
      dir: path.normalize(__dirname + '/lib'),
      pattern: 'fixtures.js'
    }
  },
  poop: {
    logPath: path.join(__dirname, 'poop.log')
  }
};

The problem seems to be the object passed as option... passing an empty object makes poop registration works but not dogwater. As stated in the docs, I'm passing the plugin name as a string and an object for the options... what am I doing wrong?

Thank you in advance!

devinivy commented 8 years ago

Hi @franzip– I think the issue is that you're passing plugin options where registration options (the second argument to server.register()) are expected. To update your example, it should look more like this,

var config = require('./config');
...
manifest: {
  server: {
  ...
  }, 
  connections: {
  ...
  },
  registrations: {
    {
      plugin: {
        register: 'dogwater',
        options: config.dogwater
      }
    },
    {
      plugin: {
        register: 'poop',
        options: config.poop
      }
    }
  }
}

Also a little heads-up as a maintainer of the boilerplate, dogwater, and bedwetter– currently dogwater v1 and bedwetter v1 are not compatible. If you want to use bedwetter, you'll have to downgrade to dogwater 0.4.x. Sorry about that! Should be fixed soon enough.

franzip commented 8 years ago

Thanks a lot @devinivy ! Heads up extremely appreciated since I was checking the various package.json to find potential incompatibilities, and I think the only constraint should be Hapi which must be <= 12 for Glue to work. I don't think I'll be using bedwetter, as I really don't need auto generated API endpoints.

devinivy commented 8 years ago

:+1: no problem @franzip!

simon-p-r commented 8 years ago

Hey @devinivy

I thought that the registrations key must have a value of an array of objects like shown below instead of an object

var config = require('./config');
...
manifest: {
  server: {
  ...
  }, 
  connections: {
  ...
  },
  registrations: [
    {
      plugin: {
        register: 'dogwater',
        options: config.dogwater
      }
    },
    {
      plugin: {
        register: 'poop',
        options: config.poop
      }
    }
  ]
}

Anyone know why this api was changed?

devinivy commented 8 years ago

One reason the API was changed is to make plugin registration order well-defined and controllable. I didn't catch that you weren't passing an array!

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.