@vrbo/catalyst-server
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -11,3 +11,3 @@ { | ||
"crumb": { | ||
"plugin": "require:crumb", | ||
"plugin": "require:@hapi/crumb", | ||
"options": "require:./plugins/config/crumb.js" | ||
@@ -14,0 +14,0 @@ }, |
@@ -17,10 +17,8 @@ /* | ||
const Joi = require('joi') | ||
const Path = require('path') | ||
const Hoek = require('@hapi/hoek') | ||
const Joi = require('@hapi/joi') | ||
const Handlers = require('shortstop-handlers') | ||
const Hoek = require('hoek') | ||
const Determination = require('determination') | ||
const Steerage = require('steerage') | ||
const Utils = require('./utils') | ||
const evalHandler = require('./shortstop/eval') | ||
@@ -92,2 +90,3 @@ const { manifestSchema, optionsSchema } = require('./schemas') | ||
// shutdown gracefully | ||
/* istanbul ignore next */ | ||
function end () { | ||
@@ -103,3 +102,5 @@ server.stop() | ||
/* istanbul ignore next */ | ||
process.once('SIGINT', end) | ||
/* istanbul ignore next */ | ||
process.once('SIGTERM', end) | ||
@@ -106,0 +107,0 @@ |
@@ -17,3 +17,3 @@ /* | ||
const Joi = require('joi') | ||
const Joi = require('@hapi/joi') | ||
@@ -35,6 +35,5 @@ const manifestSchema = Joi.object().keys({ | ||
environment: Joi.object().default(defaults.environment), | ||
shortstopHandlers: Joi.object().default(defaults.shortstopHandlers), | ||
secretsConfig: Joi.object() | ||
shortstopHandlers: Joi.object().default(defaults.shortstopHandlers) | ||
}).default(defaults) | ||
module.exports = { manifestSchema, optionsSchema } |
@@ -21,3 +21,3 @@ /* | ||
resolvePort () { | ||
return parseInt(process.env.NODE_PORT || '8080') | ||
return process.env.NODE_PORT || '8080' | ||
}, | ||
@@ -24,0 +24,0 @@ |
{ | ||
"name": "@vrbo/catalyst-server", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Configuration and composition management for Hapi.js applications.", | ||
@@ -19,6 +19,7 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test:unit": "NODE_ENV=test tape ./tests/unit/**/*.test.js | tap-spec", | ||
"test:integration": "NODE_ENV=test tape ./tests/integration/**/*.test.js | tap-spec", | ||
"test:coverage": "nyc --reporter=text --reporter=text-summary --reporter=html --lines 0 --functions 0 --branches 0 npm run test:unit", | ||
"test": "standard ./lib/**/*.js && npm run test:integration && npm run test:coverage" | ||
"build": "echo 'noop'", | ||
"test": "standard --env mocha './lib/**/*.js' './tests/**/*.js' && npm run nyc", | ||
"mocha": "mocha 'tests/**/*.js'", | ||
"nyc": "nyc --reporter=text --reporter=text-summary --reporter=html --report-dir=docs/reports/coverage npm run mocha", | ||
"postnyc": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100" | ||
}, | ||
@@ -45,21 +46,22 @@ "repository": { | ||
"peerDependencies": { | ||
"hapi": ">=17.0.0" | ||
"@hapi/hapi": ">=18.3.1" | ||
}, | ||
"devDependencies": { | ||
"hapi": "^17.8.4", | ||
"nyc": "^13.1.0", | ||
"sinon": "^7.2.2", | ||
"standard": "^12.0.1", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.9.1" | ||
"@hapi/hapi": "^18.3.1", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"nyc": "^14.1.1", | ||
"sinon": "^7.3.2", | ||
"standard": "^13.0.2", | ||
"mocha": "^6.1.4" | ||
}, | ||
"dependencies": { | ||
"crumb": "^7.2.3", | ||
"@hapi/crumb": "^7.2.3", | ||
"@hapi/hoek": "^8.0.2", | ||
"@hapi/joi": "^15.1.0", | ||
"determination": "^2.0.0", | ||
"hapi-pino": "^5.2.0", | ||
"hoek": "^6.1.2", | ||
"joi": "^14.3.0", | ||
"hapi-pino": "^6.0.1", | ||
"shortstop-handlers": "^1.0.1", | ||
"steerage": "^7.0.2" | ||
"steerage": "^8.0.0" | ||
} | ||
} |
# @vrbo/catalyst-server | ||
[![NPM Version](https://img.shields.io/npm/v/@vrbo/catalyst-server.svg?style=flat-square)](https://www.npmjs.com/package/@vrbo/catalyst-server) | ||
[![Build Status](https://travis-ci.org/homeaway/catalyst-server.svg?branch=master)](https://travis-ci.org/homeaway/catalyst-server) | ||
[![Dependency Status](https://david-dm.org/homeaway/catalyst-server.svg?theme=shields.io)](https://david-dm.org/homeaway/catalyst-server) | ||
[![NPM Downloads](https://img.shields.io/npm/dm/@vrbo/catalyst-server.svg?style=flat-square)](https://npm-stat.com/charts.html?package=@vrbo/catalyst-server) | ||
@@ -16,3 +20,3 @@ * [Introduction](#introduction) | ||
1. Install hapi and catalyst-server `npm i @vrbo/catalyst-server hapi` into an empty node project | ||
1. Install catalyst-server and hapi into an empty node project with `npm i @vrbo/catalyst-server @hapi/hapi` | ||
2. Create an `index.js` file for starting your server (example below). | ||
@@ -32,4 +36,7 @@ 3. Create a `manifest.json` for composition and configuration (example below). | ||
}); | ||
await server.start(); | ||
server.log(['info'], `server running: ${server.info.uri}`); | ||
return server; | ||
@@ -59,9 +66,9 @@ } | ||
### Basic | ||
### Basic example | ||
At its core, catalyst-server loads a `manifest.json` to initial and start a Hapi.js server. This file has a section for application configuration and composition via registering plugins. | ||
At its core, `catalyst-server` loads a `manifest.json` file to initialize and start up a Hapi.js server. This file has a section for application configuration and composition via registering plugins. | ||
Below is a basic example of a `manifest.json` file: | ||
#### Basic manifest.json | ||
#### manifest.json | ||
@@ -95,3 +102,3 @@ ```js | ||
For the configuration you can access the values in the `server/app` section from inside your code from the the `server.app.config` object. So the code to retrieve the example values look like this: | ||
You can access all the configuration values in your code from the `server.app.config` object. So the code to retrieve the example values looks like this: | ||
@@ -103,5 +110,5 @@ ```javascript | ||
The `register` block registers the plugins referenced. In this example it is using [shortstop](https://github.com/krakenjs/shortstop) to resolve node modules using `require:[module]` and resolve paths using `path:[file_path]`. | ||
The `register` block registers the plugins referenced. In this example, it is using [shortstop](https://github.com/krakenjs/shortstop) to resolve node modules using `require:[module]` and resolve paths using `path:[file_path]`. | ||
Catalyst-server comes with the following short-stop resolvers: | ||
Catalyst-server ships with the following `shortstop` resolvers by default: | ||
@@ -120,3 +127,3 @@ * __file__ - read a file. | ||
Steerage also uses [confidence](https://github.com/hapijs/confidence) to give you the ability to build environmentally aware servers. See the example `manifest.json` file below. | ||
`Steerage` uses [confidence](https://github.com/hapijs/confidence) to give you the ability to build environmentally aware servers. See the example `manifest.json` file below. | ||
@@ -156,4 +163,8 @@ #### Environment based manifest.json | ||
Here you can see the `$filter` and `$default` fields. These fields allow for filtering on a resolver like `env.NODE_ENV`. The `$filter` field evaluates the environment variable `NODE_ENV`. Then it will look to the following fields for a match in the keys for that value, otherwise the `$default` value is used. So the configuration values and options for plugins will change based on the environment variable `NODE_ENV`. You could also determine whether plugin should be registered at all. See the code below for an example based on this `manifest.json` file. | ||
In this example, the `$filter` and `$default` fields allow for filtering based on a resolver like `env.NODE_ENV`. | ||
The `$filter` field evaluates the environment variable `NODE_ENV`. Then, it will look to the following fields for a match in the keys for that value. Otherwise, the `$default` value is used. So the configuration values and options for plugins will change based on the environment variable `NODE_ENV`. | ||
This is what the above manifest configuration will return in code for different environments: | ||
```javascript | ||
@@ -171,5 +182,21 @@ // ENVIRONMENT VARIABLE NODE_ENV='development' | ||
Using a filter, you can easily enable/disable a plugin for a given environment. See the code below for an example, where we disable `hapi-pino` in development mode, and enable it in all other environments: | ||
```javascript | ||
{ | ||
"register": { | ||
"hapi-pino": { | ||
"enabled": { | ||
"$filter": "env.NODE_ENV", | ||
"development": false, | ||
"$default": true | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
### Advanced | ||
Here are some examples of the short-stop resolvers available that makes handling complex configuration and composition rather straight forward. | ||
Here are some examples of the `shortstop` resolvers which make handling complex configuration and composition rather straight forward. | ||
@@ -244,7 +271,7 @@ #### `file:` Reading a file into a value. | ||
* eval can also be used to reference other values in the `manifest`. In the above example the `child/value` in `server/app` will be set to `'abc_xyz'`. | ||
* `eval` can also be used to reference other values in the `manifest`. In the above example the `child/value` in `server/app` will be set to `'abc_xyz'`. | ||
## Example Code | ||
See the [examples folder](examples) for an example. | ||
See the [examples](examples) folder for example code. | ||
@@ -251,0 +278,0 @@ ## Further Reading |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43587
27
508
274
7
2
+ Added@hapi/crumb@^7.2.3
+ Added@hapi/hoek@^8.0.2
+ Added@hapi/joi@^15.1.0
+ Added@hapi/accept@6.0.3(transitive)
+ Added@hapi/address@2.1.4(transitive)
+ Added@hapi/ammo@6.0.1(transitive)
+ Added@hapi/b64@6.0.1(transitive)
+ Added@hapi/boom@10.0.17.4.11(transitive)
+ Added@hapi/bounce@3.0.2(transitive)
+ Added@hapi/bourne@1.3.23.0.0(transitive)
+ Added@hapi/call@9.0.1(transitive)
+ Added@hapi/catbox@12.1.1(transitive)
+ Added@hapi/content@6.0.0(transitive)
+ Added@hapi/crumb@7.3.2(transitive)
+ Added@hapi/cryptiles@4.2.16.0.1(transitive)
+ Added@hapi/file@3.0.0(transitive)
+ Added@hapi/formula@1.2.0(transitive)
+ Added@hapi/hapi@21.3.12(transitive)
+ Added@hapi/heavy@8.0.1(transitive)
+ Added@hapi/hoek@11.0.78.5.1(transitive)
+ Added@hapi/iron@7.0.1(transitive)
+ Added@hapi/joi@15.1.116.1.8(transitive)
+ Added@hapi/mimos@7.0.1(transitive)
+ Added@hapi/nigel@5.0.1(transitive)
+ Added@hapi/pez@6.1.0(transitive)
+ Added@hapi/pinpoint@1.0.2(transitive)
+ Added@hapi/podium@5.0.1(transitive)
+ Added@hapi/shot@6.0.1(transitive)
+ Added@hapi/somever@4.1.1(transitive)
+ Added@hapi/statehood@8.1.1(transitive)
+ Added@hapi/subtext@8.1.0(transitive)
+ Added@hapi/teamwork@6.0.0(transitive)
+ Added@hapi/topo@3.1.66.0.2(transitive)
+ Added@hapi/validate@2.0.1(transitive)
+ Added@hapi/vise@5.0.1(transitive)
+ Addeddetermination@3.0.0(transitive)
+ Addedhapi-pino@6.5.0(transitive)
+ Addedjoycon@2.2.5(transitive)
+ Addedpino-pretty@3.6.1(transitive)
+ Addedsteerage@8.1.1(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
- Removedcrumb@^7.2.3
- Removedhoek@^6.1.2
- Removedjoi@^14.3.0
- Removedaccept@3.1.3(transitive)
- Removedammo@3.0.3(transitive)
- Removedb64@4.1.2(transitive)
- Removedboom@7.3.0(transitive)
- Removedbounce@1.2.3(transitive)
- Removedbourne@1.3.3(transitive)
- Removedcall@5.0.3(transitive)
- Removedcatbox@10.0.6(transitive)
- Removedcatbox-memory@4.0.1(transitive)
- Removedcontent@4.0.6(transitive)
- Removedcrumb@7.2.3(transitive)
- Removedcryptiles@4.1.3(transitive)
- Removedfast-json-parse@1.0.3(transitive)
- Removedhapi@18.1.0(transitive)
- Removedhapi-pino@5.4.1(transitive)
- Removedheavy@6.1.2(transitive)
- Removedhoek@5.0.46.1.3(transitive)
- Removediron@5.0.6(transitive)
- Removedisemail@3.2.0(transitive)
- Removedjoi@13.7.014.3.1(transitive)
- Removedmimos@4.0.2(transitive)
- Removednigel@3.0.4(transitive)
- Removedpez@4.0.5(transitive)
- Removedpino-pretty@2.6.1(transitive)
- Removedpodium@3.2.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedshot@4.0.7(transitive)
- Removedsomever@2.0.0(transitive)
- Removedstatehood@6.0.9(transitive)
- Removedsteerage@7.0.3(transitive)
- Removedsubtext@6.0.12(transitive)
- Removedteamwork@3.2.0(transitive)
- Removedtopo@3.0.3(transitive)
- Removedvise@3.0.2(transitive)
- Removedwreck@14.2.0(transitive)
Updatedhapi-pino@^6.0.1
Updatedsteerage@^8.0.0