![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
cascading-service-config
Advanced tools
is a format for a versatile configuration file that configures more than one http service in a single system.
npm install cascading-service-config
Lets say we have an example config with two services and an authentication module (which requires a config) that both services depend on, as well as some shared settings. Our config might look like this:
var configSource = {
logmethod: "syslog", // a shared setting
auth: {
cookie: "authKey",
storage: {
type: "redis",
location: "localhost:6789"
}
},
service1: {
port: 8402,
logmethod: "loggly",
wibblewobbles: true
},
service2: {
port: 8403
}
}
Now we can give this to CSC, as well as a domain - the domain is just the name of the service which is currently reading the config.
var config = require('cascading-service-config')(configSource, 'service1');
Now we have our config object. The properties which you have access to look like
this (but this is different to what you'll get if you console.log
it, as we
are making using of prototypical inheritance):
{
logmethod: "loggly", // note that we overrode the shared setting here
auth: {
service1: "http://localhost:8402",
service2: "http://localhost:8403",
logmethod: "syslog",
auth: [circular reference],
cookie: "authKey",
storage: { type: "redis", location: "localhost:6789" }
},
service1: "http://localhost:8402",
service2: "http://localhost:8403",
wibblewobbles: true,
port: 8402
}
Because we specified service1
as our domain, that's is our top-level config
object. All properties in the service1
object of the config source are passed
verbatim to the final config.
However, under this, we have two objects which we inherit.
{ service1: "http://localhost:8402", service2: "http://localhost:8403" }
-
CSC looks through each of the objects on the root level of the config. If an
object has a port
setting, it is assumed to be a service. This object
consists of assembled access points for each of the other services in your
domain, so that they're easily accessible on your config.Also note that each other object on the root config also gains the same prototype
chain, so in our example, auth
also gained the service locations.
In our example, the prototype chain looks something like this:
{ wibblewobbles: true, logmethod: "loggly", port: 8402 }
// inherits...
{ service1: "http://localhost:8402", service2: "http://localhost:8403" }
// inherits...
{ auth: { ... }, logmethod: "syslog", service1: { ... }, service2: { ... } }
http
or localhost
No problem! There's two special config options you can use to configure this:
internalServiceHostname
and internalServiceProtocol
. You can configure this
globally or per-object. In our example, we could set:
{
logmethod: "syslog"
internalServiceHostname: "amazing.service.com",
internalServiceProtocol: "https",
...
Which, in our final config, would result in...
console.log(config.service2);
// -> 'https://amazing.service.com:8403'
But what if service1 is running on http, not https? Well, we can override the
root internalServiceProtocol
in service1
's config:
...
service1: {
internalServiceProtocol: "http",
port: 8402,
...
Resulting in...
console.log(config.service1);
// -> 'http://amazing.service.com:8402'
console.log(config.service2);
// -> 'https://amazing.service.com:8403'
It's possible, but very much discouraged (as you'll see from the syntax). Config formats change, and depending upon another service's config format is usually a pretty bad idea.
However, if you absolutely must do it, there are two ways.
You could access the source config object by traversing the prototype chain:
console.log(config.__proto__.__proto__.service2.port);
// -> 8403
Or you could just call CSC again and specify the domain of the other service:
var service2config = require('cascading-service-config')(configSource, 'service2');
console.log(service2config.port);
// -> 8403
csc(configSourceObject, [domain])
Reads a cascading service config file and returns a config for the given domain. If the domain does not exist, the root config is returned.
FAQs
dry configuration for a multi-service system
We found that cascading-service-config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.