From 65996e72e0b09b8ca09f56fcb4125cfde0ec16fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Fri, 5 Feb 2021 11:30:30 +0100 Subject: [PATCH] fix: add unleashUrl option --- docs/configuring-unleash.md | 5 +++-- lib/addons/jira-comment.js | 2 +- lib/addons/slack.js | 2 +- lib/addons/slack.test.js | 22 +++++++++++++++++----- lib/addons/slack.test.js.md | 2 +- lib/addons/slack.test.js.snap | Bin 377 -> 372 bytes lib/options.js | 1 + lib/services/addon-service.js | 11 +++++++---- 8 files changed, 31 insertions(+), 14 deletions(-) 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 884a47a44bcb1eeeeb093a8c5016c459bd1c53ae..0b80da9cf33d19c8ecbf81cebbda378fc5210c75 100644 GIT binary patch literal 372 zcmV-)0gL`YRzV zkg-k!F${+9K)}QRGe}X`D$4CAgkb0lLzyVhH0SnG<(yN_si<0BfH&eHcm~*5cmo!k zwxS)FNQT&7emn6mk|ar!U01xles&)A)0dCq!}p^!iR+t>?PPBer#s2P)>k@{p#hJo z0-4KOw4j<&o=T$~K0@WjhH)O2Jm(97Ct}pN3NB;inRb=X9uz?#hI|AMg4}3iL7bOF zb)IEW+z#GGZFZ8aR87{9=dzKBVU#S(<{R-v4_h5n0}Dkf7wE)Xw7Sz8I0;z5&>+9c z?8dt>XxhYFd8Nrr6d8wN{S<5Z{eD}-k#oUf6)g3T8BeE6g$R}hJo#~*R)EyV z{B9G%DUB1-Nm=pK3&&G@mY9p_`sg$2GVFx+? Sm#6aip7#&aU0y^R0ssL13aknM literal 377 zcmV-<0fzoTRzVP)ViwyLXCI3Q00000000A> zkiAaBFc5$f5HK;o43cHGiV~^nWFZ7YXBf&vfx6DMapl;NeXgilUVt~^A$SJZSa}1u zv=!~ZggxBdcmKzdBuSH9m%qJ!b{_WAmyhGa_oFna-#3ZvWN)FTJITS;S32V{fVZ*) zF8HlAAVa}VxmM0TLg~huu!u`8$bs;Lgn}#Kvd%nHu4KxCM9A5YMD)PWjYbC8d4X7o zEHh3?Q@DVl-Dm9z!V*!c zq6CY9i@O<@sxG?JSI1i|)m@CezSMOEmTAk@w?!JC9D|7HEZGxj;$H; { try { - const provider = new Provider({ getLogger }); + const provider = new Provider(config); // eslint-disable-next-line no-param-reassign map[provider.name] = provider; } finally {