diff --git a/docs/configuring-unleash.md b/docs/configuring-unleash.md index 0391e037f7..ba4b4d284a 100644 --- a/docs/configuring-unleash.md +++ b/docs/configuring-unleash.md @@ -3,7 +3,7 @@ id: configuring_unleash title: Configuring Unleash --- -In order to custimize "anything" in Unleash you need to use [Unleash from Node.js](./getting_started#option-two---from-nodejs): +In order to customize "anything" in Unleash you need to use [Unleash from Node.js](./getting_started#option-two---from-nodejs): ```js const unleash = require('unleash-server'); @@ -50,11 +50,12 @@ unleash.start(unleashOptions); - **getLogger** (function) - Used to register a [custom log provider](#how-do-i-configure-the-log-output). - **eventHook** (`function(event, data)`) - If provided, this function will be invoked whenever a feature is mutated. The possible values for `event` are `'feature-created'`, `'feature-updated'`, `'feature-archived'`, `'feature-revived'`. The `data` argument contains information about the mutation. Its fields are `type` (string) - the event type (same as `event`); `createdBy` (string) - the user who performed the mutation; `data` - the contents of the change. The contents in `data` differs based on the event type; For `'feature-archived'` and `'feature-revived'`, the only field will be `name` - the name of the feature. For `'feature-created'` and `'feature-updated'` the data follows a schema defined in the code [here](https://github.com/Unleash/unleash/blob/master/lib/routes/admin-api/feature-schema.js#L38-L59). See an example [here](./guides/feature-updates-to-slack.md). - **baseUriPath** (string) - use to register a base path for all routes on the application. For example `/my/unleash/base` (note the starting /). Defaults to `/`. Can also be configured through the environment variable `BASE_URI_PATH`. +- **unleashUrl** (string) - Used to specify the official URL this instance of Unleash can be accessed at for an end user. Can also be configured through the environment variable `UNLEASH_URL`. - **secureHeaders** (boolean) - use this to enable security headers (HSTS, CSP, etc) when serving Unleash from HTTPS. Can also be configured through the environment variable `SECURE_HEADERS`. ### Disabling Auto-Start -If you're using Unleash as part of a larger express app, you can disable the automatic server start by calling `server.create`. It takes the same options as `sevrer.start`, but will not begin listening for connections. +If you're using Unleash as part of a larger express app, you can disable the automatic server start by calling `server.create`. It takes the same options as `server.start`, but will not begin listening for connections. ```js const unleash = require('unleash-server'); diff --git a/lib/addons/jira-comment.js b/lib/addons/jira-comment.js index 1b273994c4..c20d0f733f 100644 --- a/lib/addons/jira-comment.js +++ b/lib/addons/jira-comment.js @@ -12,7 +12,7 @@ const { class JiraAddon extends Addon { constructor(args) { super(definition, args); - this.unleashUrl = args.unleashUrl || 'http://localhost:4242'; + this.unleashUrl = args.unleashUrl; } async handleEvent(event, parameters) { diff --git a/lib/addons/slack.js b/lib/addons/slack.js index f1109e47d9..d61157e68e 100644 --- a/lib/addons/slack.js +++ b/lib/addons/slack.js @@ -15,7 +15,7 @@ const definition = require('./slack-definition'); class SlackAddon extends Addon { constructor(args) { super(definition, args); - this.unleashUrl = args.unleashUrl || 'http://localhost:4242'; + this.unleashUrl = args.unleashUrl; } async handleEvent(event, parameters) { diff --git a/lib/addons/slack.test.js b/lib/addons/slack.test.js index cb8fe8c0dc..4e908b3896 100644 --- a/lib/addons/slack.test.js +++ b/lib/addons/slack.test.js @@ -2,7 +2,7 @@ const test = require('ava'); const proxyquire = require('proxyquire').noCallThru(); const { FEATURE_CREATED } = require('../event-type'); -const WebhookAddon = proxyquire.load('./slack', { +const SlackAddon = proxyquire.load('./slack', { './addon': class Addon { constructor(definition, { getLogger }) { this.logger = getLogger('addon/test'); @@ -19,7 +19,10 @@ const WebhookAddon = proxyquire.load('./slack', { const noLogger = require('../../test/fixtures/no-logger'); test('Should call slack webhook', async t => { - const addon = new WebhookAddon({ getLogger: noLogger }); + const addon = new SlackAddon({ + getLogger: noLogger, + unleashUrl: 'http://some-url.com', + }); const event = { type: FEATURE_CREATED, createdBy: 'some@user.com', @@ -41,7 +44,10 @@ test('Should call slack webhook', async t => { }); test('Should use default channel', async t => { - const addon = new WebhookAddon({ getLogger: noLogger }); + const addon = new SlackAddon({ + getLogger: noLogger, + unleashUrl: 'http://some-url.com', + }); const event = { type: FEATURE_CREATED, createdBy: 'some@user.com', @@ -65,7 +71,10 @@ test('Should use default channel', async t => { }); test('Should override default channel with data from tag', async t => { - const addon = new WebhookAddon({ getLogger: noLogger }); + const addon = new SlackAddon({ + getLogger: noLogger, + unleashUrl: 'http://some-url.com', + }); const event = { type: FEATURE_CREATED, createdBy: 'some@user.com', @@ -95,7 +104,10 @@ test('Should override default channel with data from tag', async t => { }); test('Should post to all channels in tags', async t => { - const addon = new WebhookAddon({ getLogger: noLogger }); + const addon = new SlackAddon({ + getLogger: noLogger, + unleashUrl: 'http://some-url.com', + }); const event = { type: FEATURE_CREATED, createdBy: 'some@user.com', diff --git a/lib/addons/slack.test.js.md b/lib/addons/slack.test.js.md index 6dd2ece24a..e7c767a452 100644 --- a/lib/addons/slack.test.js.md +++ b/lib/addons/slack.test.js.md @@ -8,4 +8,4 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - '{"username":"Unleash","icon_emoji":":unleash:","text":"some@user.com created feature toggle \\n*Enabled*: no | *Type*: undefined | *Project*: undefined\\n*Activation strategies*: ```- name: default\\n```","channel":"#undefined","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://localhost:4242/#/features/strategies/some-toggle"}]}]}' + '{"username":"Unleash","icon_emoji":":unleash:","text":"some@user.com created feature toggle \\n*Enabled*: no | *Type*: undefined | *Project*: undefined\\n*Activation strategies*: ```- name: default\\n```","channel":"#undefined","attachments":[{"actions":[{"name":"featureToggle","text":"Open in Unleash","type":"button","value":"featureToggle","style":"primary","url":"http://some-url.com/#/features/strategies/some-toggle"}]}]}' diff --git a/lib/addons/slack.test.js.snap b/lib/addons/slack.test.js.snap index 884a47a44b..0b80da9cf3 100644 Binary files a/lib/addons/slack.test.js.snap and b/lib/addons/slack.test.js.snap differ diff --git a/lib/options.js b/lib/options.js index f7fb21e8b7..de4b83ef34 100644 --- a/lib/options.js +++ b/lib/options.js @@ -40,6 +40,7 @@ function defaultOptions() { host: process.env.HTTP_HOST, pipe: undefined, baseUriPath: process.env.BASE_URI_PATH || '', + unleashUrl: process.env.UNLEASH_URL || 'http://localhost:4242', serverMetrics: true, enableLegacyRoutes: false, extendedPermissions: false, diff --git a/lib/services/addon-service.js b/lib/services/addon-service.js index c01decdfc0..e5ad6b02e1 100644 --- a/lib/services/addon-service.js +++ b/lib/services/addon-service.js @@ -15,7 +15,7 @@ const MASKED_VALUE = '*****'; class AddonService { constructor( { addonStore, eventStore, featureToggleStore }, - { getLogger }, + { getLogger, unleashUrl }, tagTypeService, ) { this.eventStore = eventStore; @@ -25,7 +25,10 @@ class AddonService { this.logger = getLogger('services/addon-service.js'); this.tagTypeService = tagTypeService; - this.addonProviders = this.loadProviders(getLogger); + this.addonProviders = this.loadProviders({ + getLogger, + unleashUrl, + }); this.sensitiveParams = this.loadSensitiveParams(this.addonProviders); if (addonStore) { this.registerEventHandler(); @@ -38,10 +41,10 @@ class AddonService { ); } - loadProviders(getLogger) { + loadProviders(config) { return addonProvidersClasses.reduce((map, Provider) => { try { - const provider = new Provider({ getLogger }); + const provider = new Provider(config); // eslint-disable-next-line no-param-reassign map[provider.name] = provider; } finally {