GithubHelp home page GithubHelp logo

Comments (6)

mtharrison avatar mtharrison commented on September 26, 2024

Is this code that you want to execute after all plugins have loaded? If so how about putting it in the Glue.compose callback?

Glue.compose(manifest, options, (err, server) => {

    if (err) {
        throw err;  // an error loading one of the plugins
    }

    // do thing here

    server.start((err) => {

        if (err) {
            throw err;
        }
        console.log('hapi days!');
    });
});

If you want the code to execute as part of the individual plugin loading you can just add it to that plugin's register function.

exports.register = function (server, options, next) {

    // do thing here

    next();
}

from glue.

snig-b avatar snig-b commented on September 26, 2024

Right... That works. But another problem is that the next() call is breaking for me. When I run the server it says, invalid plug in options register must be a function. And when i remove this method call - next() it executes perfectly. Can you figure out what may be the issue?

from glue.

mtharrison avatar mtharrison commented on September 26, 2024

It's a bit tricky to figure out based on just the code that you've posted. Can you share more? Or if not can you make an example showing the same issue that you can share.

Is ./some-module the only plugin in the manifest? What does it export?

from glue.

snig-b avatar snig-b commented on September 26, 2024

No.. I have registered multiple plugins. More specifically, I am following the structure shared on https://medium.com/@dstevensio/manifests-plugins-and-schemas-organizing-your-hapi-application-68cf316730ef#.dbxxrz2yz for logical modules as plugins. index.js for these plugins is more or less similar to the one shown here. Only difference being how I have registered them -

registrations: [
        {
            plugin:  {
                register: "./module1",
                options: {
                    database: database,
                    redis: redis
                }
            },
            options: {
                select: ['module1']
            }
        },
        {
            plugin: {
                register: './module2',
                options: {
                    database: database,
                    redis: redis
                }
            },
            options: {
                select: ['module2']
            }
        },
        {
            plugin: {
                register: "./module3",
                options: {
                    database: database,
                    redis: redis
                }
            },
            options: {
                select: ['module3']
            }
        },
        {
            plugin: {
                register: 'good',
                options: {
                // Logging & monitoring.
                reporters: [{
                    reporter: require('good-console'),
                    events: {
                        response: '*',
                        log: '*'
                    }
                }]
            }
            }

        }
    ]

Problem is occurring in my internal plugins only, not the external ones - like 'good'.
These plugins' register function export a couple of server routes using 'namespace' utility.

This is my error log:

/home/snigi/Projects/.../node_modules/hapi/node_modules/hoek/lib/index.js:732
    throw new Error(msgs.join(' ') || 'Unknown error');
    ^

Error: Invalid plugin options {
  "options": {
    "database": {},
    "redis": {
      "redis0": {
        "domain": null,
        "_events": {},
        "_eventsCount": 1,
        "options": {
          "port": 6379,
          "host": "localhost",
          "family": 4,
          "connectTimeout": 3000,
          "keepAlive": 0,
          "connectionName": null,
          "sentinels": null,
          "name": null,
          "role": "master",
          "password": null,
          "db": 0,
          "parser": "auto",
          "enableOfflineQueue": true,
          "enableReadyCheck": true,
          "autoResubscribe": true,
          "autoResendUnfulfilledCommands": true,
          "lazyConnect": false,
          "keyPrefix": "",
          "reconnectOnError": null
        },
        "scriptsSet": {},
        "commandQueue": [],
        "offlineQueue": [
          {
            "command": {
              "name": "subscribe",
              "replyEncoding": "utf8",
              "args": [
                "news",
                "music"
              ],
              "transformed": true,
              "promise": {
                "isFulfilled": false,
                "isRejected": false
              }
            },
            "select": 0
          }
        ],
        "connector": {
          "options": {
            "port": 6379,
            "host": "localhost",
            "family": 4,
            "connectTimeout": 3000,
            "keepAlive": 0,
            "connectionName": null,
            "sentinels": null,
            "name": null,
            "role": "master",
            "password": null,
            "db": 0,
            "parser": "auto",
            "enableOfflineQueue": true,
            "enableReadyCheck": true,
            "autoResubscribe": true,
            "autoResendUnfulfilledCommands": true,
            "lazyConnect": false,
            "keyPrefix": "",
            "reconnectOnError": null
          },
          "connecting": true
        },
        "retryAttempts": 0,
        "status": "connecting",
        "condition": {
          "select": 0,
          "auth": null,
          "subscriber": false
        }
      },
      "someconnection": {
        "domain": null,
        "_events": {},
        "_eventsCount": 0,
        "options": {
          "host": "some-ip",
          "port": 6379,
          "db": 1,
          "family": 4,
          "connectTimeout": 3000,
          "keepAlive": 0,
          "connectionName": null,
          "sentinels": null,
          "name": null,
          "role": "master",
          "password": null,
          "parser": "auto",
          "enableOfflineQueue": true,
          "enableReadyCheck": true,
          "autoResubscribe": true,
          "autoResendUnfulfilledCommands": true,
          "lazyConnect": false,
          "keyPrefix": "",
          "reconnectOnError": null
        },
        "scriptsSet": {},
        "commandQueue": [],
        "offlineQueue": [],
        "connector": {
          "options": {
            "host": "some-ip",
            "port": 6379,
            "db": 1,
            "family": 4,
            "connectTimeout": 3000,
            "keepAlive": 0,
            "connectionName": null,
            "sentinels": null,
            "name": null,
            "role": "master",
            "password": null,
            "parser": "auto",
            "enableOfflineQueue": true,
            "enableReadyCheck": true,
            "autoResubscribe": true,
            "autoResendUnfulfilledCommands": true,
            "lazyConnect": false,
            "keyPrefix": "",
            "reconnectOnError": null
          },
          "connecting": true
        },
        "retryAttempts": 0,
        "status": "connecting",
        "condition": {
          "select": 1,
          "auth": null,
          "subscriber": false
        }
      },
      "someconnection2": {
        "domain": null,
        "_events": {},
        "_eventsCount": 0,
        "options": {
          "host": "some-ip",
          "port": 6379,
          "db": 15,
          "family": 4,
          "connectTimeout": 3000,
          "keepAlive": 0,
          "connectionName": null,
          "sentinels": null,
          "name": null,
          "role": "master",
          "password": null,
          "parser": "auto",
          "enableOfflineQueue": true,
          "enableReadyCheck": true,
          "autoResubscribe": true,
          "autoResendUnfulfilledCommands": true,
          "lazyConnect": false,
          "keyPrefix": "",
          "reconnectOnError": null
        },
        "scriptsSet": {},
        "commandQueue": [],
        "offlineQueue": [],
        "connector": {
          "options": {
            "host": "some-ip",
            "port": 6379,
            "db": 15,
            "family": 4,
            "connectTimeout": 3000,
            "keepAlive": 0,
            "connectionName": null,
            "sentinels": null,
            "name": null,
            "role": "master",
            "password": null,
            "parser": "auto",
            "enableOfflineQueue": true,
            "enableReadyCheck": true,
            "autoResubscribe": true,
            "autoResendUnfulfilledCommands": true,
            "lazyConnect": false,
            "keyPrefix": "",
            "reconnectOnError": null
          },
          "connecting": true
        },
        "retryAttempts": 0,
        "status": "connecting",
        "condition": {
          "select": 15,
          "auth": null,
          "subscriber": false
        }
      },
      "pub": {
        "domain": null,
        "_events": {},
        "_eventsCount": 0,
        "options": {
          "port": 6379,
          "host": "localhost",
          "family": 4,
          "connectTimeout": 3000,
          "keepAlive": 0,
          "connectionName": null,
          "sentinels": null,
          "name": null,
          "role": "master",
          "password": null,
          "db": 0,
          "parser": "auto",
          "enableOfflineQueue": true,
          "enableReadyCheck": true,
          "autoResubscribe": true,
          "autoResendUnfulfilledCommands": true,
          "lazyConnect": false,
          "keyPrefix": "",
          "reconnectOnError": null
        },
        "scriptsSet": {},
        "commandQueue": [],
        "offlineQueue": [],
        "connector": {
          "options": {
            "port": 6379,
            "host": "localhost",
            "family": 4,
            "connectTimeout": 3000,
            "keepAlive": 0,
            "connectionName": null,
            "sentinels": null,
            "name": null,
            "role": "master",
            "password": null,
            "db": 0,
            "parser": "auto",
            "enableOfflineQueue": true,
            "enableReadyCheck": true,
            "autoResubscribe": true,
            "autoResendUnfulfilledCommands": true,
            "lazyConnect": false,
            "keyPrefix": "",
            "reconnectOnError": null
          },
          "connecting": true
        },
        "retryAttempts": 0,
        "status": "connecting",
        "condition": {
          "select": 0,
          "auth": null,
          "subscriber": false
        }
      }
    }
  },
  "register" [1]: {}
}

[1] "register" must be a Function
    at Object.exports.contain.exports.reachTemplate.exports.assert.condition [as assert] (/home/snigi/Projects/.../node_modules/hapi/node_modules/hoek/lib/index.js:732:11)
    at Object.exports.apply (/home/snigi/Projects/.../node_modules/hapi/lib/schema.js:17:10)
    at module.exports.internals.Plugin.internals.Plugin.register.each [as register] (/home/snigi/Projects/.../node_modules/hapi/lib/plugin.js:226:25)
    at /home/snigi/Projects/.../node_modules/glue/lib/index.js:119:24
    at iterate (/home/snigi/Projects/.../node_modules/glue/node_modules/items/lib/index.js:36:13)
    at done (/home/snigi/Projects/.../node_modules/glue/node_modules/items/lib/index.js:28:25)
    at /home/snigi/Projects/.../node_modules/hapi/lib/plugin.js:326:16
    at done (/home/snigi/Projects/.../node_modules/hapi/node_modules/items/lib/index.js:31:25)
    at Object.exports.register (/home/snigi/Projects/.../src/modules/module2/index.js:34:5)
    at Object.target [as register] (/home/snigi/Projects/.../node_modules/hapi/node_modules/joi/lib/object.js:80:30)
    at each (/home/snigi/Projects/.../node_modules/hapi/lib/plugin.js:320:14)
    at iterate (/home/snigi/Projects/.../node_modules/hapi/node_modules/items/lib/index.js:36:13)
    at Object.exports.serial (/home/snigi/Projects/.../node_modules/hapi/node_modules/items/lib/index.js:39:9)
    at module.exports.internals.Plugin.internals.Plugin.register.each [as register] (/home/snigi/Projects/.../node_modules/hapi/lib/plugin.js:323:11)
    at /home/snigi/Projects/.../node_modules/glue/lib/index.js:119:24
    at iterate (/home/snigi/Projects/.../node_modules/glue/node_modules/items/lib/index.js:36:13)

Apologies for such a long post.

from glue.

snig-b avatar snig-b commented on September 26, 2024

I figured out the problem, the index.js of one of the plugins was missing the register function by mistake.
The bug here is irrelevant, however the error traceback was nowhere leading me to the issue.
The error was being thrown from an altogether different plugin.
Anyways, thank you so much for the help, you can please close this issue.

from glue.

lock avatar lock commented on September 26, 2024

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.

from glue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.