@trenskow/app-express 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. package/index.js +8 -0
  2. package/package.json +1 -1
  3. package/test.js +17 -0
package/index.js CHANGED
@@ -9,7 +9,13 @@
9
9
  export default ({ Router, util: { resolveInlineImport } }) => {
10
10
 
11
11
  Router.prototype.express = function(router) {
12
+
12
13
  router = resolveInlineImport(router);
14
+
15
+ if (Array.isArray(router)) return router.reduce((last, router) => {
16
+ return last.express(router);
17
+ }, this);
18
+
13
19
  this._layers.push({
14
20
  handler: (_, __, { ignore, request, response }, next) => {
15
21
 
@@ -57,7 +63,9 @@ export default ({ Router, util: { resolveInlineImport } }) => {
57
63
 
58
64
  }
59
65
  });
66
+
60
67
  return this;
68
+
61
69
  };
62
70
 
63
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/app-express",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A plugin for `@trenskow/app` that allows for using routes for express.`",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -48,6 +48,23 @@ describe('app-express', () => {
48
48
 
49
49
  });
50
50
 
51
+ it ('should handle an array of routes', async () => {
52
+
53
+ app.root(
54
+ new Endpoint()
55
+ .express([
56
+ (_, __, next) => next(),
57
+ (_, __, next) => next(),
58
+ (_, res) => res.send('ok')
59
+ ])
60
+ );
61
+
62
+ await request
63
+ .get('/')
64
+ .expect(200, 'ok');
65
+
66
+ });
67
+
51
68
  it ('should handle error from express route', async () => {
52
69
  app.root(
53
70
  new Endpoint()