@trenskow/app-express 0.0.2 → 0.0.5

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "caseit"
4
+ ]
5
+ }
package/index.js CHANGED
@@ -6,13 +6,27 @@
6
6
  // For license see LICENSE.
7
7
  //
8
8
 
9
+ import caseit from '@trenskow/caseit';
10
+
9
11
  export default ({ Router, util: { resolveInlineImport } }) => {
10
12
 
11
13
  Router.prototype.express = function(router) {
14
+
12
15
  router = resolveInlineImport(router);
16
+
17
+ if (Array.isArray(router)) return router.reduce((last, router) => {
18
+ return last.express(router);
19
+ }, this);
20
+
13
21
  this._layers.push({
14
22
  handler: (_, __, { ignore, request, response }, next) => {
15
23
 
24
+ const headers = request.headers;
25
+
26
+ request.headers = Object.fromEntries(
27
+ Object.entries(headers)
28
+ .map(([key, value]) => [caseit(key, 'kebab'), value]));
29
+
16
30
  return new Promise((resolve, reject) => {
17
31
 
18
32
  const writeHeadEventHandler = () => {
@@ -43,6 +57,8 @@ export default ({ Router, util: { resolveInlineImport } }) => {
43
57
 
44
58
  response.removeListener('writeHead', writeHeadEventHandler);
45
59
 
60
+ request.headers = headers;
61
+
46
62
  if (error) return reject(error);
47
63
 
48
64
  resolve(next());
@@ -57,7 +73,9 @@ export default ({ Router, util: { resolveInlineImport } }) => {
57
73
 
58
74
  }
59
75
  });
76
+
60
77
  return this;
78
+
61
79
  };
62
80
 
63
81
  };
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.5",
4
4
  "description": "A plugin for `@trenskow/app` that allows for using routes for express.`",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,5 +27,8 @@
27
27
  "chai": "^4.3.6",
28
28
  "mocha": "^10.0.0",
29
29
  "supertest": "^6.2.4"
30
+ },
31
+ "dependencies": {
32
+ "@trenskow/caseit": "^1.3.3"
30
33
  }
31
34
  }
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()