1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: add unleashUrl option

This commit is contained in:
Ivar Conradi Østhus 2021-02-05 11:30:30 +01:00
parent 2bb38fe3e8
commit 65996e72e0
8 changed files with 31 additions and 14 deletions

View File

@ -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');

View File

@ -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) {

View File

@ -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) {

View File

@ -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',

View File

@ -8,4 +8,4 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
'{"username":"Unleash","icon_emoji":":unleash:","text":"some@user.com created feature toggle <http://localhost:4242/#/features/strategies/some-toggle|some-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 <http://some-url.com/#/features/strategies/some-toggle|some-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"}]}]}'

Binary file not shown.

View File

@ -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,

View File

@ -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 {