unleash-server 3.3.6 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.4.0
4
+
5
+ - feat: Adds server.create() (#606)
6
+
3
7
  ## 3.3.6
4
8
 
5
9
  - fix: upgrade unleash-frontend to verson 3.3.5
package/README.md CHANGED
@@ -55,7 +55,7 @@ Clients written by awesome enthusiasts: :fire:
55
55
  - [uekoetter.dev/unleash-client-dart](https://pub.dev/packages/unleash) (Dart)
56
56
  - [minds/unleash-client-php](https://gitlab.com/minds/unleash-client-php) (PHP)
57
57
  - [afontaine/unleash_ex](https://gitlab.com/afontaine/unleash_ex) (Elixir)
58
- - [mikefrancis/laravel-unleash](https://github.com/mikefrancis/laravel-unleash) (Larvel - PHP)
58
+ - [mikefrancis/laravel-unleash](https://github.com/mikefrancis/laravel-unleash) (Laravel - PHP)
59
59
 
60
60
  ### The Client API
61
61
 
@@ -61,6 +61,25 @@ Available unleash options include:
61
61
  - **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/feautre-updates-to-slack.md).
62
62
  - **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`.
63
63
 
64
+ #### Disabling Auto-Start
65
+
66
+ 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.
67
+
68
+ ```js
69
+ const unleash = require('unleash-server');
70
+ // ... const app = express();
71
+
72
+ unleash
73
+ .create({
74
+ databaseUrl: 'postgres://unleash_user:password@localhost:5432/unleash',
75
+ port: 4242,
76
+ })
77
+ .then(result => {
78
+ app.use(result.app);
79
+ console.log(`Unleash app generated and attached to parent application`);
80
+ });
81
+ ```
82
+
64
83
  ### 3. Docker
65
84
 
66
85
  You can also use the [hosted docker image](https://hub.docker.com/r/unleashorg/unleash-server/) to start the Unleash server
package/lib/options.js CHANGED
@@ -51,6 +51,7 @@ function defaultOptions() {
51
51
  getLogger: defaultLogProvider,
52
52
  customContextFields: [],
53
53
  disableDBMigration: false,
54
+ start: true,
54
55
  };
55
56
  }
56
57
 
@@ -53,22 +53,26 @@ async function createApp(options) {
53
53
  });
54
54
  }
55
55
 
56
- const server = app.listen(options.listen, () =>
57
- logger.info('Unleash has started.', server.address()),
58
- );
59
-
60
56
  return new Promise((resolve, reject) => {
61
- server.on('listening', () =>
62
- resolve({
63
- app,
64
- config,
65
- stores,
66
- server,
67
- eventBus,
68
- stateService,
69
- }),
70
- );
71
- server.on('error', reject);
57
+ const payload = {
58
+ app,
59
+ config,
60
+ stores,
61
+ eventBus,
62
+ stateService,
63
+ };
64
+
65
+ if (options.start) {
66
+ const server = app.listen(options.listen, () =>
67
+ logger.info('Unleash has started.', server.address()),
68
+ );
69
+ server.on('listening', () => {
70
+ resolve({ ...payload, server });
71
+ });
72
+ server.on('error', reject);
73
+ } else {
74
+ resolve({ ...payload });
75
+ }
72
76
  });
73
77
  }
74
78
 
@@ -90,8 +94,13 @@ async function start(opts) {
90
94
  return createApp(options);
91
95
  }
92
96
 
97
+ async function create(opts) {
98
+ return start({ ...opts, start: false });
99
+ }
100
+
93
101
  module.exports = {
94
102
  start,
103
+ create,
95
104
  User,
96
105
  AuthenticationRequired,
97
106
  permissions,
@@ -82,3 +82,20 @@ test('should call eventHook', async t => {
82
82
  eventStore.emit('feature-created', {});
83
83
  t.true(called === 1);
84
84
  });
85
+
86
+ test('should auto-create server on start()', async t => {
87
+ const { server } = await serverImpl.start({
88
+ port: 0,
89
+ getLogger,
90
+ start: true,
91
+ });
92
+ t.false(typeof server === 'undefined');
93
+ });
94
+
95
+ test('should not create a server using create()', async t => {
96
+ const { server } = await serverImpl.create({
97
+ port: 0,
98
+ getLogger,
99
+ });
100
+ t.true(typeof server === 'undefined');
101
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unleash-server",
3
3
  "description": "Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.",
4
- "version": "3.3.6",
4
+ "version": "3.4.0",
5
5
  "keywords": [
6
6
  "unleash",
7
7
  "feature toggle",