outmoded / rejoice Goto Github PK
View Code? Open in Web Editor NEWhapi.js CLI
License: Other
hapi.js CLI
License: Other
So I was looking through the source trying to trace down how to setup our modules to work both in development and in production where the paths for plugins can be drastically different. Ideally using the -p
option should take care of this.
However while I was looking I found this segment of code
internals.parseEnv = function (manifest) {
if (!manifest ||
typeof manifest !== 'object') {
return;
}
Object.keys(manifest).forEach(function (key) {
var value = manifest[key];
if (typeof value === 'string' &&
value.indexOf('$env.') === 0) {
manifest[key] = process.env[value.slice(5)];
}
else {
internals.parseEnv(value);
}
});
};
This appears to search for keys in the manifest file that start with $env.
and does substitution on a key with a value specified in the process environment. Is this documented somewhere or did I miss it?
I'm trying to implement rejoice but I'm having a problem.
I got a manifest file called ./config.json
.
I'm calling node rejoice -c config.json
and getting
Error: Cannot find module 'D:\Projects\metaphor\rejoice'
I thought maybe it couldn't find node_modules
so I tried
node rejoice -c config.json -p /node_modules
but that didn't work either.
So what am I doing wrong? :)
I'm not sure if you're familiar with newrelic.js for Hapi or how it's implemented. However in the simpliest of implementations it only requires the inclusion of require('newrelic');
in you hapi server.
I've tried something similar to the following:
rejoice -c manifest.json -r 'path/to/newrelic'
Unfortunately I received the following response from the newrelic agent log.
{"v":0,"level":40,"name":"newrelic","hostname":"hostname","pid":1549,"time":"2015-09-18T21:52:24.200Z","msg":"The newrelic module must be the first module required.\nThe following modules were required before newrelic and are not being instrumented:\n\thapi"}
Seems like it's not possible and that my only option is to include there require('newrelic')
either in a new hapi plugin definition, use a start.js script, or include the require('newrelic')
in an existing plugin.
Thoughts?
I'm in the process of a PR to separate the behavior of -p
and -p
+ -r
into another command-line option.
I'm seeking guidance on the typical use case:
rejoice -c config.json -p ./lib
rejoice -c config.json -r module -r module
-p
and use ./node_modules
as the location for -r
rejoice -c config.json -r module -p path_to_base_dir_node_modules_used_by_dash_r
-r
and -p
together.Need to add some documentation with examples
https://github.com/hapijs/rejoice/blob/master/test/rejoice.js#L249
When an error occurs this can cause the tests to still succeed because they are overriding the process.exit function.
Hi!
I'm sure I'm missing something obvious, but it isn't clear to me how the JSON configuration file listed in the README hooks up with the JavaScript file I assume must exist somewhere defining routes, etc. Would it be possible to have a 'full-stack' example? Or am I entirely misunderstanding how rejoice is to be used?
I read over the documentation for rejoice -p option:
You can specify a specific node_modules top level path by using the -p
flag.
rejoice -c app.json -p /full/path/node_modules
This is in contridiction to the code here:
https://github.com/hapijs/rejoice/blob/master/lib/index.js#L46-L48
The code performs a Path.join(*, 'node_modules')
. There fore the result of the example above would be /full/path/node_modules/node_modules
.
I am new to the hapi universe and giving rejoice a try, I encountered this error:
module.js:327
throw err;
^
Error: Cannot find module 'vision'
[...]
when trying to launch it with
rejoice -c manifest.json
and a few variations with -p [DIRECTORY], always getting the same error.
I already had a manifest.json file, which I've attached. I'm also attaching the simple glue script I am using (before turning to rejoice) which works as expected.
vision and other required npm modules are all referenced in package.json and installed.
Oh well, attaching files isn't working for me now, so here we go:
manifest.json:
{
"connections": [ { "port": 8800 } ],
"registrations": [
{ "plugin": "vision" },
{
"plugin": {
"register": "visionary",
"options": {
"engines": { "pug": "pug" },
"path": "tpls"
}
}
},
{
"plugin": { "register": "./routes/bap" },
"options": { "routes": { "prefix": "/woot" } }
},
{ "plugin": "./routes/home" },
{
"plugin": {
"register": "good",
"options": {
"reporters": {
"console": [
{
"module": "good-squeeze",
"name": "Squeeze",
"args": [{
"response": "*",
"log": "*"
}]
},
{ "module": "good-console" },
"stdout"
]
}
}
}
}
]
}
server.js: (my current alternative to rejoice)
'use strict'
const Glue = require('glue')
Glue.compose(require('./manifest.json'), { relativeTo: __dirname })
.then((server) => {
server.start()
return server
})
.then((server) => {
console.log('hapi days!', server.info.uri)
})
.catch((err) => {
console.error('ERROR:', err)
})
Sometimes it's impossible to define all plugins via glue's manifest,
(i.e when a method should be referenced by the plugin options)
It could be nice if rejoice could support hooks where plugins can be registered programmatically, maybe by leveraging glue's preConnections
/ prePlugins
hooks.
Thanks.
It would be nice to support Confidence format for the manifest, using JSON is too limited.
Example:
If I use the good plugin with a custom reporter, the path to load the reporter is relative to the rejoice directory, not to the manifest file directory, so that's confusing. With Confidence I could use absolute path with __dirname
in the manifest file.
I would like my configuration file to reference JSON environment variables. I don’t believe Rejoice can handle this:
"plugins": { "dbModule": "$env.jsonEnvVariable" }
where jsonEnvVariable
is a list of db connection details as such:
[{"options":{"name":"db1", ... }}
,{"options":{"name":"db2", ...}}]
Rejoice passes this environment variable one time into the dbModule register function as a string (as expected). I would like it to call the dbModule register function twice, once for each option object (how it behaves if the JSON is hardcoded). This would allow me to continue leveraging the simplicity of Rejoice for configuration setup rather than handling this in the dbModule.
My suggestion for a fix:
Rejoice's parseEnv function (line 110) could check if
process.env[value.slice(5)]
returns valid JSON, and if so,
JSON.parse
the key value rather than keep it a string.
Something like this:
try{
manifest[key] = JSON.parse(process.env[value.slice(5)]);
}
catch(e){
manifest[key] = process.env[value.slice(5)];
}
Anyone using this module? Time to deprecate?
If not, please open a hapi v17 issue to migrate.
The latest version, 3.3.0, fails on install, at least on linux based systems. I am seeing the following output on npm install both on my local development environment (ubuntu trusty64 build) and in our travis environment. Version 3.2.0, which was the most recent version until earlier this morning, still installs just fine.
npm install [email protected]
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN [email protected] No repository field.
npm ERR! Linux 3.13.0-87-generic
npm ERR! argv "/home/vagrant/.nvm/versions/node/v5.11.1/bin/node" "/home/vagrant/.nvm/versions/node/v5.11.1/bin/npm" "install" "[email protected]"
npm ERR! node v5.11.1
npm ERR! npm v3.8.6
npm ERR! path /vagrant/node_modules/rejoice/bin/rejoice
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/vagrant/node_modules/rejoice/bin/rejoice'
npm ERR! enoent ENOENT: no such file or directory, chmod '/vagrant/node_modules/rejoice/bin/rejoice'
would you accept a PR for supporting a manifest file in YAML format?
I'm not seeing a whole lot on how to configure the rejoice server, In addition, I want to add more data to the config, but when I try to place my data key somewhere I keep getting things like:
Error: Invalid server options {
"load": {
"sampleInterval": 1000
},
"remoteAPI" [1]: "https://xxxsss.api.xxxsss.com/v1/xxxxxsss"
}
or Invalid manifest
Closed by #19.
Is there/can there be a way to pass arguments on to Node (for instance to set Node's debug port). For instance if I had rejoice -c manifest.js -p . -- --debug-brk=5959
as the target of a run script, everything after --
would be passed directly to Node.
I posted a work-around on StackOverflow, but having a cleaner syntax[1] would be nicer.
[1] Reaching into node_modules/.bin
feels wrong and possibly brittle, and it side-steps one of the major benefits to using run scripts in the first place.
es 6, node 4.x, new hapi styles. Note: awaiting a glue PR hapijs/glue#42 to get glue upgraded at the same time. Please do not merge until this has been done and I will include that.
Would you accept a PR for loading .js file ?
Why?
I would like to use some values based on environments, for example i want to run on the port 1337 if is local and 80 if production, this just an example but give you an idea why i would like to have that feature.
Thanks.
Looks like there is a new glue and other updates to dependencies. This is always a breaking change as with glue, you don't need to include which hapi version you are using.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.