Comments (6)
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.
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.
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.
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.
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.
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)
- how do you pass in concurrent option to hapi? HOT 4
- Should we have a "ISSUE_TEMPLATE.md" for Glue? HOT 1
- How should I use routes in server config (failAction). HOT 3
- Add hook to transform plugin list before registration HOT 17
- Integration with webpack - dynamic import issue HOT 4
- Make hapi a peer dependency HOT 7
- Error: Cannot start server before plugins finished registration HOT 4
- Using glue with hapi-mongoose HOT 5
- server.events is undefined after glue compose HOT 5
- Server options load support? Migrating from hapi 16 -> 17 HOT 6
- Change module namespace HOT 1
- Change module namespace for v5 branch HOT 1
- Server cache options in hapi 18 cannot be passed HOT 3
- Action required: Greenkeeper could not be activated 🚨 HOT 1
- Update deps HOT 1
- Update joi HOT 1
- Add typescript type definitions HOT 2
- Only node 12
- No way of passing default route validator to glue HOT 1
- plugin.name is required
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glue.