@teambit/express 0.0.689 → 0.0.691
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/dist/express.aspect.js +0 -5
- package/dist/express.aspect.js.map +1 -1
- package/dist/express.composition.js +0 -6
- package/dist/express.composition.js.map +1 -1
- package/dist/express.main.runtime.js +5 -57
- package/dist/express.main.runtime.js.map +1 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +1 -1
- package/dist/middlewares/error.js +4 -10
- package/dist/middlewares/error.js.map +1 -1
- package/dist/middlewares/index.js +0 -3
- package/dist/middlewares/index.js.map +1 -1
- package/dist/types/index.js +0 -12
- package/dist/types/index.js.map +1 -1
- package/dist/types/route.js +0 -3
- package/dist/types/route.js.map +1 -1
- package/package-tar/teambit-express-0.0.691.tgz +0 -0
- package/package.json +5 -5
- package/{preview-1666409808293.js → preview-1666755696699.js} +2 -2
- package/package-tar/teambit-express-0.0.689.tgz +0 -0
package/dist/express.aspect.js
CHANGED
@@ -4,23 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.ExpressAspect = void 0;
|
7
|
-
|
8
7
|
function _harmony() {
|
9
8
|
const data = require("@teambit/harmony");
|
10
|
-
|
11
9
|
_harmony = function () {
|
12
10
|
return data;
|
13
11
|
};
|
14
|
-
|
15
12
|
return data;
|
16
13
|
}
|
17
|
-
|
18
14
|
const ExpressAspect = _harmony().Aspect.create({
|
19
15
|
id: 'teambit.harmony/express',
|
20
16
|
dependencies: [],
|
21
17
|
defaultConfig: {}
|
22
18
|
});
|
23
|
-
|
24
19
|
exports.ExpressAspect = ExpressAspect;
|
25
20
|
|
26
21
|
//# sourceMappingURL=express.aspect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ExpressAspect","Aspect","create","id","dependencies","defaultConfig"],"sources":["express.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const ExpressAspect = Aspect.create({\n id: 'teambit.harmony/express',\n dependencies: [],\n defaultConfig: {},\n});\n"],"mappings":"
|
1
|
+
{"version":3,"names":["ExpressAspect","Aspect","create","id","dependencies","defaultConfig"],"sources":["express.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const ExpressAspect = Aspect.create({\n id: 'teambit.harmony/express',\n dependencies: [],\n defaultConfig: {},\n});\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,aAAa,GAAGC,iBAAM,CAACC,MAAM,CAAC;EACzCC,EAAE,EAAE,yBAAyB;EAC7BC,YAAY,EAAE,EAAE;EAChBC,aAAa,EAAE,CAAC;AAClB,CAAC,CAAC;AAAC"}
|
@@ -1,22 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.Logo = void 0;
|
9
|
-
|
10
8
|
function _react() {
|
11
9
|
const data = _interopRequireDefault(require("react"));
|
12
|
-
|
13
10
|
_react = function () {
|
14
11
|
return data;
|
15
12
|
};
|
16
|
-
|
17
13
|
return data;
|
18
14
|
}
|
19
|
-
|
20
15
|
const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
21
16
|
style: {
|
22
17
|
height: '100%',
|
@@ -29,7 +24,6 @@ const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
29
24
|
},
|
30
25
|
src: "https://static.bit.dev/extensions-icons/express.svg"
|
31
26
|
}));
|
32
|
-
|
33
27
|
exports.Logo = Logo;
|
34
28
|
|
35
29
|
//# sourceMappingURL=express.composition.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["express.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/express.svg\" />\n </div>\n);\n"],"mappings":"
|
1
|
+
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["express.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/express.svg\" />\n </div>\n);\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,IAAI,GAAG,mBAClB;EAAK,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAM;IAAEC,OAAO,EAAE,MAAM;IAAEC,cAAc,EAAE;EAAS;AAAE,gBACxE;EAAK,KAAK,EAAE;IAAEC,KAAK,EAAE;EAAG,CAAE;EAAC,GAAG,EAAC;AAAqD,EAAG,CAE1F;AAAC"}
|
@@ -1,120 +1,84 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
require("core-js/modules/es.array.flat-map.js");
|
6
|
-
|
7
5
|
require("core-js/modules/es.array.iterator.js");
|
8
|
-
|
9
6
|
require("core-js/modules/es.array.unscopables.flat-map.js");
|
10
|
-
|
11
7
|
require("core-js/modules/es.promise.js");
|
12
|
-
|
13
8
|
Object.defineProperty(exports, "__esModule", {
|
14
9
|
value: true
|
15
10
|
});
|
16
11
|
exports.ExpressMain = void 0;
|
17
|
-
|
18
12
|
function _defineProperty2() {
|
19
13
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
20
|
-
|
21
14
|
_defineProperty2 = function () {
|
22
15
|
return data;
|
23
16
|
};
|
24
|
-
|
25
17
|
return data;
|
26
18
|
}
|
27
|
-
|
28
19
|
function _cli() {
|
29
20
|
const data = require("@teambit/cli");
|
30
|
-
|
31
21
|
_cli = function () {
|
32
22
|
return data;
|
33
23
|
};
|
34
|
-
|
35
24
|
return data;
|
36
25
|
}
|
37
|
-
|
38
26
|
function _harmony() {
|
39
27
|
const data = require("@teambit/harmony");
|
40
|
-
|
41
28
|
_harmony = function () {
|
42
29
|
return data;
|
43
30
|
};
|
44
|
-
|
45
31
|
return data;
|
46
32
|
}
|
47
|
-
|
48
33
|
function _logger() {
|
49
34
|
const data = require("@teambit/logger");
|
50
|
-
|
51
35
|
_logger = function () {
|
52
36
|
return data;
|
53
37
|
};
|
54
|
-
|
55
38
|
return data;
|
56
39
|
}
|
57
|
-
|
58
40
|
function _express() {
|
59
41
|
const data = _interopRequireDefault(require("express"));
|
60
|
-
|
61
42
|
_express = function () {
|
62
43
|
return data;
|
63
44
|
};
|
64
|
-
|
65
45
|
return data;
|
66
46
|
}
|
67
|
-
|
68
47
|
function _lodash() {
|
69
48
|
const data = require("lodash");
|
70
|
-
|
71
49
|
_lodash = function () {
|
72
50
|
return data;
|
73
51
|
};
|
74
|
-
|
75
52
|
return data;
|
76
53
|
}
|
77
|
-
|
78
54
|
function _bodyParser() {
|
79
55
|
const data = _interopRequireDefault(require("body-parser"));
|
80
|
-
|
81
56
|
_bodyParser = function () {
|
82
57
|
return data;
|
83
58
|
};
|
84
|
-
|
85
59
|
return data;
|
86
60
|
}
|
87
|
-
|
88
61
|
function _express2() {
|
89
62
|
const data = require("./express.aspect");
|
90
|
-
|
91
63
|
_express2 = function () {
|
92
64
|
return data;
|
93
65
|
};
|
94
|
-
|
95
66
|
return data;
|
96
67
|
}
|
97
|
-
|
98
68
|
function _middlewares() {
|
99
69
|
const data = require("./middlewares");
|
100
|
-
|
101
70
|
_middlewares = function () {
|
102
71
|
return data;
|
103
72
|
};
|
104
|
-
|
105
73
|
return data;
|
106
74
|
}
|
107
|
-
|
108
75
|
function _types() {
|
109
76
|
const data = require("./types");
|
110
|
-
|
111
77
|
_types = function () {
|
112
78
|
return data;
|
113
79
|
};
|
114
|
-
|
115
80
|
return data;
|
116
81
|
}
|
117
|
-
|
118
82
|
class ExpressMain {
|
119
83
|
constructor(
|
120
84
|
/**
|
@@ -134,36 +98,32 @@ class ExpressMain {
|
|
134
98
|
this.logger = logger;
|
135
99
|
this.middlewareSlot = middlewareSlot;
|
136
100
|
}
|
101
|
+
|
137
102
|
/**
|
138
103
|
* start a express server.
|
139
104
|
*/
|
140
|
-
|
141
|
-
|
142
105
|
async listen(port) {
|
143
106
|
const serverPort = port || this.config.port;
|
144
107
|
const app = this.createApp();
|
145
108
|
app.listen(serverPort);
|
146
109
|
}
|
110
|
+
|
147
111
|
/**
|
148
112
|
* register a new express routes.
|
149
113
|
* route will be added as `/api/${route}`
|
150
114
|
*/
|
151
|
-
|
152
|
-
|
153
115
|
register(routes) {
|
154
116
|
this.moduleSlot.register(routes);
|
155
117
|
return this;
|
156
118
|
}
|
119
|
+
|
157
120
|
/**
|
158
121
|
* register a new middleware into express.
|
159
122
|
*/
|
160
|
-
|
161
|
-
|
162
123
|
registerMiddleware(middlewares) {
|
163
124
|
this.middlewareSlot.register(middlewares);
|
164
125
|
return this;
|
165
126
|
}
|
166
|
-
|
167
127
|
createRootRoutes() {
|
168
128
|
// TODO: @guy refactor health to service aspect.
|
169
129
|
return [{
|
@@ -174,7 +134,6 @@ class ExpressMain {
|
|
174
134
|
middlewares: [async (req, res) => res.send('ok')]
|
175
135
|
}];
|
176
136
|
}
|
177
|
-
|
178
137
|
createApp(expressApp, options) {
|
179
138
|
const internalRoutes = this.createRootRoutes();
|
180
139
|
const routes = this.createRoutes();
|
@@ -193,14 +152,13 @@ class ExpressMain {
|
|
193
152
|
path,
|
194
153
|
middlewares,
|
195
154
|
disableNamespace
|
196
|
-
} = routeInfo;
|
197
|
-
|
155
|
+
} = routeInfo;
|
156
|
+
// TODO: @guy make sure to support single middleware here.
|
198
157
|
const namespace = disableNamespace ? '' : `/${this.config.namespace}`;
|
199
158
|
app[method](`${namespace}${path}`, this.catchErrorsMiddlewares(middlewares));
|
200
159
|
});
|
201
160
|
return app;
|
202
161
|
}
|
203
|
-
|
204
162
|
createRoutes() {
|
205
163
|
const routesSlots = this.moduleSlot.toArray();
|
206
164
|
const routeEntries = routesSlots.map(([, routes]) => {
|
@@ -216,13 +174,10 @@ class ExpressMain {
|
|
216
174
|
});
|
217
175
|
return (0, _lodash().flatten)(routeEntries);
|
218
176
|
}
|
219
|
-
|
220
177
|
verbValidation(route) {
|
221
178
|
return async (req, res, next) => {
|
222
179
|
if (!route.verb) return next();
|
223
|
-
|
224
180
|
const verb = req.headers['x-verb'] || _types().Verb.READ;
|
225
|
-
|
226
181
|
if (verb !== route.verb) {
|
227
182
|
res.status(403);
|
228
183
|
return res.jsonp({
|
@@ -230,15 +185,12 @@ class ExpressMain {
|
|
230
185
|
error: 'forbidden'
|
231
186
|
});
|
232
187
|
}
|
233
|
-
|
234
188
|
return next();
|
235
189
|
};
|
236
190
|
}
|
237
|
-
|
238
191
|
catchErrorsMiddlewares(middlewares) {
|
239
192
|
return middlewares.map(middleware => (0, _middlewares().catchErrors)(middleware));
|
240
193
|
}
|
241
|
-
|
242
194
|
bodyParser(app) {
|
243
195
|
app.use(_bodyParser().default.json({
|
244
196
|
limit: '5000mb'
|
@@ -248,14 +200,11 @@ class ExpressMain {
|
|
248
200
|
limit: '5000mb'
|
249
201
|
}));
|
250
202
|
}
|
251
|
-
|
252
203
|
static async provider([loggerFactory], config, [routeSlot, middlewareSlot]) {
|
253
204
|
const logger = loggerFactory.createLogger(_express2().ExpressAspect.id);
|
254
205
|
return new ExpressMain(config, routeSlot, logger, middlewareSlot);
|
255
206
|
}
|
256
|
-
|
257
207
|
}
|
258
|
-
|
259
208
|
exports.ExpressMain = ExpressMain;
|
260
209
|
(0, _defineProperty2().default)(ExpressMain, "runtime", _cli().MainRuntime);
|
261
210
|
(0, _defineProperty2().default)(ExpressMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
|
@@ -265,7 +214,6 @@ exports.ExpressMain = ExpressMain;
|
|
265
214
|
namespace: 'api',
|
266
215
|
loggerIgnorePath: ['/api/_health']
|
267
216
|
});
|
268
|
-
|
269
217
|
_express2().ExpressAspect.addRuntime(ExpressMain);
|
270
218
|
|
271
219
|
//# sourceMappingURL=express.main.runtime.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ExpressMain","constructor","config","moduleSlot","logger","middlewareSlot","listen","port","serverPort","app","createApp","register","routes","registerMiddleware","middlewares","createRootRoutes","namespace","ExpressAspect","id","method","path","disableNamespace","req","res","send","expressApp","options","internalRoutes","createRoutes","allRoutes","concat","express","use","next","loggerIgnorePath","includes","url","debug","headers","disableBodyParser","bodyParser","toArray","flatMap","middlewareManifest","middleware","forEach","routeInfo","catchErrorsMiddlewares","routesSlots","routeEntries","map","route","flatten","verbValidation","lowerCase","verb","Verb","READ","status","jsonp","message","error","catchErrors","json","limit","raw","type","provider","loggerFactory","routeSlot","createLogger","MainRuntime","Slot","withType","LoggerAspect","addRuntime"],"sources":["express.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport express, { Express } from 'express';\nimport { concat, flatten, lowerCase } from 'lodash';\nimport bodyParser from 'body-parser';\nimport { ExpressAspect } from './express.aspect';\nimport { catchErrors } from './middlewares';\nimport { Middleware, Request, Response, Route, Verb } from './types';\nimport { MiddlewareManifest } from './middleware-manifest';\n\nexport type ExpressConfig = {\n port: number;\n namespace: string;\n loggerIgnorePath: string[];\n};\n\nexport type MiddlewareSlot = SlotRegistry<MiddlewareManifest[]>;\n\nexport type RouteSlot = SlotRegistry<Route[]>;\n\nexport class ExpressMain {\n static runtime = MainRuntime;\n\n constructor(\n /**\n * extension config\n */\n readonly config: ExpressConfig,\n\n /**\n * slot for registering graphql modules\n */\n private moduleSlot: RouteSlot,\n\n /**\n * logger extension.\n */\n readonly logger: Logger,\n\n readonly middlewareSlot: MiddlewareSlot\n ) {}\n\n /**\n * start a express server.\n */\n async listen(port?: number) {\n const serverPort = port || this.config.port;\n const app = this.createApp();\n app.listen(serverPort);\n }\n\n /**\n * register a new express routes.\n * route will be added as `/api/${route}`\n */\n register(routes: Route[]) {\n this.moduleSlot.register(routes);\n return this;\n }\n\n /**\n * register a new middleware into express.\n */\n registerMiddleware(middlewares: MiddlewareManifest[]) {\n this.middlewareSlot.register(middlewares);\n return this;\n }\n\n private createRootRoutes() {\n // TODO: @guy refactor health to service aspect.\n return [\n {\n namespace: ExpressAspect.id,\n method: 'get',\n path: '/_health',\n disableNamespace: false,\n middlewares: [async (req: Request, res: Response) => res.send('ok')],\n },\n ];\n }\n\n createApp(expressApp?: Express, options?: { disableBodyParser: true }): Express {\n const internalRoutes = this.createRootRoutes();\n const routes = this.createRoutes();\n const allRoutes = concat(routes, internalRoutes);\n const app = expressApp || express();\n app.use((req, res, next) => {\n if (this.config.loggerIgnorePath.includes(req.url)) return next();\n this.logger.debug(`express got a request to a URL: ${req.url}', headers:`, req.headers);\n return next();\n });\n if (!options?.disableBodyParser) this.bodyParser(app);\n\n this.middlewareSlot\n .toArray()\n .flatMap(([, middlewares]) =>\n middlewares.flatMap((middlewareManifest) => app.use(middlewareManifest.middleware))\n );\n allRoutes.forEach((routeInfo) => {\n const { method, path, middlewares, disableNamespace } = routeInfo;\n // TODO: @guy make sure to support single middleware here.\n const namespace = disableNamespace ? '' : `/${this.config.namespace}`;\n app[method](`${namespace}${path}`, this.catchErrorsMiddlewares(middlewares));\n });\n\n return app;\n }\n\n private createRoutes() {\n const routesSlots = this.moduleSlot.toArray();\n const routeEntries = routesSlots.map(([, routes]) => {\n return routes.map((route) => {\n const middlewares = flatten([this.verbValidation(route), route.middlewares]);\n return {\n method: lowerCase(route.method),\n path: route.route,\n disableNamespace: route.disableNamespace,\n middlewares,\n };\n });\n });\n\n return flatten(routeEntries);\n }\n\n private verbValidation(route: Route): Middleware {\n return async (req: express.Request, res: express.Response, next: express.NextFunction) => {\n if (!route.verb) return next();\n const verb = req.headers['x-verb'] || Verb.READ;\n if (verb !== route.verb) {\n res.status(403);\n return res.jsonp({ message: 'You are not authorized', error: 'forbidden' });\n }\n return next();\n };\n }\n\n private catchErrorsMiddlewares(middlewares: Middleware[]) {\n return middlewares.map((middleware) => catchErrors(middleware));\n }\n\n private bodyParser(app: Express) {\n app.use(bodyParser.json({ limit: '5000mb' }));\n app.use(bodyParser.raw({ type: 'application/octet-stream', limit: '5000mb' }));\n }\n\n static slots = [Slot.withType<Route[]>(), Slot.withType<MiddlewareManifest[]>()];\n static dependencies = [LoggerAspect];\n\n static defaultConfig = {\n port: 4001,\n namespace: 'api',\n loggerIgnorePath: ['/api/_health'],\n };\n\n static async provider(\n [loggerFactory]: [LoggerMain],\n config: ExpressConfig,\n [routeSlot, middlewareSlot]: [RouteSlot, MiddlewareSlot]\n ) {\n const logger = loggerFactory.createLogger(ExpressAspect.id);\n return new ExpressMain(config, routeSlot, logger, middlewareSlot);\n }\n}\n\nExpressAspect.addRuntime(ExpressMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAaO,MAAMA,WAAN,CAAkB;EAGvBC,WAAW;EACT;AACJ;AACA;EACaC,MAJA;EAMT;AACJ;AACA;EACYC,UATC;EAWT;AACJ;AACA;EACaC,MAdA,EAgB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I,EAAE,0BAAR;MAAoCF,KAAK,EAAE;IAA3C,CAAf,CAAR;EACD;;EAWoB,aAARG,QAAQ,CACnB,CAACC,aAAD,CADmB,EAEnBlE,MAFmB,EAGnB,CAACmE,SAAD,EAAYhE,cAAZ,CAHmB,EAInB;IACA,MAAMD,MAAM,GAAGgE,aAAa,CAACE,YAAd,CAA2BrD,yBAAA,CAAcC,EAAzC,CAAf;IACA,OAAO,IAAIlB,WAAJ,CAAgBE,MAAhB,EAAwBmE,SAAxB,EAAmCjE,MAAnC,EAA2CC,cAA3C,CAAP;EACD;;AA9IsB;;;gCAAZL,W,aACMuE,kB;gCADNvE,W,WA8HI,CAACwE,eAAA,CAAKC,QAAL,EAAD,EAA2BD,eAAA,CAAKC,QAAL,EAA3B,C;gCA9HJzE,W,kBA+HW,CAAC0E,sBAAD,C;gCA/HX1E,W,mBAiIY;EACrBO,IAAI,EAAE,IADe;EAErBS,SAAS,EAAE,KAFU;EAGrBkB,gBAAgB,EAAE,CAAC,cAAD;AAHG,C;;AAgBzBjB,yBAAA,CAAc0D,UAAd,CAAyB3E,WAAzB"}
|
1
|
+
{"version":3,"names":["ExpressMain","constructor","config","moduleSlot","logger","middlewareSlot","listen","port","serverPort","app","createApp","register","routes","registerMiddleware","middlewares","createRootRoutes","namespace","ExpressAspect","id","method","path","disableNamespace","req","res","send","expressApp","options","internalRoutes","createRoutes","allRoutes","concat","express","use","next","loggerIgnorePath","includes","url","debug","headers","disableBodyParser","bodyParser","toArray","flatMap","middlewareManifest","middleware","forEach","routeInfo","catchErrorsMiddlewares","routesSlots","routeEntries","map","route","flatten","verbValidation","lowerCase","verb","Verb","READ","status","jsonp","message","error","catchErrors","json","limit","raw","type","provider","loggerFactory","routeSlot","createLogger","MainRuntime","Slot","withType","LoggerAspect","addRuntime"],"sources":["express.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport express, { Express } from 'express';\nimport { concat, flatten, lowerCase } from 'lodash';\nimport bodyParser from 'body-parser';\nimport { ExpressAspect } from './express.aspect';\nimport { catchErrors } from './middlewares';\nimport { Middleware, Request, Response, Route, Verb } from './types';\nimport { MiddlewareManifest } from './middleware-manifest';\n\nexport type ExpressConfig = {\n port: number;\n namespace: string;\n loggerIgnorePath: string[];\n};\n\nexport type MiddlewareSlot = SlotRegistry<MiddlewareManifest[]>;\n\nexport type RouteSlot = SlotRegistry<Route[]>;\n\nexport class ExpressMain {\n static runtime = MainRuntime;\n\n constructor(\n /**\n * extension config\n */\n readonly config: ExpressConfig,\n\n /**\n * slot for registering graphql modules\n */\n private moduleSlot: RouteSlot,\n\n /**\n * logger extension.\n */\n readonly logger: Logger,\n\n readonly middlewareSlot: MiddlewareSlot\n ) {}\n\n /**\n * start a express server.\n */\n async listen(port?: number) {\n const serverPort = port || this.config.port;\n const app = this.createApp();\n app.listen(serverPort);\n }\n\n /**\n * register a new express routes.\n * route will be added as `/api/${route}`\n */\n register(routes: Route[]) {\n this.moduleSlot.register(routes);\n return this;\n }\n\n /**\n * register a new middleware into express.\n */\n registerMiddleware(middlewares: MiddlewareManifest[]) {\n this.middlewareSlot.register(middlewares);\n return this;\n }\n\n private createRootRoutes() {\n // TODO: @guy refactor health to service aspect.\n return [\n {\n namespace: ExpressAspect.id,\n method: 'get',\n path: '/_health',\n disableNamespace: false,\n middlewares: [async (req: Request, res: Response) => res.send('ok')],\n },\n ];\n }\n\n createApp(expressApp?: Express, options?: { disableBodyParser: true }): Express {\n const internalRoutes = this.createRootRoutes();\n const routes = this.createRoutes();\n const allRoutes = concat(routes, internalRoutes);\n const app = expressApp || express();\n app.use((req, res, next) => {\n if (this.config.loggerIgnorePath.includes(req.url)) return next();\n this.logger.debug(`express got a request to a URL: ${req.url}', headers:`, req.headers);\n return next();\n });\n if (!options?.disableBodyParser) this.bodyParser(app);\n\n this.middlewareSlot\n .toArray()\n .flatMap(([, middlewares]) =>\n middlewares.flatMap((middlewareManifest) => app.use(middlewareManifest.middleware))\n );\n allRoutes.forEach((routeInfo) => {\n const { method, path, middlewares, disableNamespace } = routeInfo;\n // TODO: @guy make sure to support single middleware here.\n const namespace = disableNamespace ? '' : `/${this.config.namespace}`;\n app[method](`${namespace}${path}`, this.catchErrorsMiddlewares(middlewares));\n });\n\n return app;\n }\n\n private createRoutes() {\n const routesSlots = this.moduleSlot.toArray();\n const routeEntries = routesSlots.map(([, routes]) => {\n return routes.map((route) => {\n const middlewares = flatten([this.verbValidation(route), route.middlewares]);\n return {\n method: lowerCase(route.method),\n path: route.route,\n disableNamespace: route.disableNamespace,\n middlewares,\n };\n });\n });\n\n return flatten(routeEntries);\n }\n\n private verbValidation(route: Route): Middleware {\n return async (req: express.Request, res: express.Response, next: express.NextFunction) => {\n if (!route.verb) return next();\n const verb = req.headers['x-verb'] || Verb.READ;\n if (verb !== route.verb) {\n res.status(403);\n return res.jsonp({ message: 'You are not authorized', error: 'forbidden' });\n }\n return next();\n };\n }\n\n private catchErrorsMiddlewares(middlewares: Middleware[]) {\n return middlewares.map((middleware) => catchErrors(middleware));\n }\n\n private bodyParser(app: Express) {\n app.use(bodyParser.json({ limit: '5000mb' }));\n app.use(bodyParser.raw({ type: 'application/octet-stream', limit: '5000mb' }));\n }\n\n static slots = [Slot.withType<Route[]>(), Slot.withType<MiddlewareManifest[]>()];\n static dependencies = [LoggerAspect];\n\n static defaultConfig = {\n port: 4001,\n namespace: 'api',\n loggerIgnorePath: ['/api/_health'],\n };\n\n static async provider(\n [loggerFactory]: [LoggerMain],\n config: ExpressConfig,\n [routeSlot, middlewareSlot]: [RouteSlot, MiddlewareSlot]\n ) {\n const logger = loggerFactory.createLogger(ExpressAspect.id);\n return new ExpressMain(config, routeSlot, logger, middlewareSlot);\n }\n}\n\nExpressAspect.addRuntime(ExpressMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;A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C3E,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
@@ -45,34 +45,25 @@ Object.defineProperty(exports, "Verb", {
|
|
45
45
|
return _types().Verb;
|
46
46
|
}
|
47
47
|
});
|
48
|
-
|
49
48
|
function _expressMain() {
|
50
49
|
const data = require("./express.main.runtime");
|
51
|
-
|
52
50
|
_expressMain = function () {
|
53
51
|
return data;
|
54
52
|
};
|
55
|
-
|
56
53
|
return data;
|
57
54
|
}
|
58
|
-
|
59
55
|
function _types() {
|
60
56
|
const data = require("./types");
|
61
|
-
|
62
57
|
_types = function () {
|
63
58
|
return data;
|
64
59
|
};
|
65
|
-
|
66
60
|
return data;
|
67
61
|
}
|
68
|
-
|
69
62
|
function _express() {
|
70
63
|
const data = require("./express.aspect");
|
71
|
-
|
72
64
|
_express = function () {
|
73
65
|
return data;
|
74
66
|
};
|
75
|
-
|
76
67
|
return data;
|
77
68
|
}
|
78
69
|
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { RouteSlot } from './express.main.runtime';\nexport { Route, Verb } from './types';\nexport { Request, Response, NextFunction } from './types';\nexport type { ExpressMain } from './express.main.runtime';\nexport { ExpressAspect } from './express.aspect';\n"],"mappings":"
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { RouteSlot } from './express.main.runtime';\nexport { Route, Verb } from './types';\nexport { Request, Response, NextFunction } from './types';\nexport type { ExpressMain } from './express.main.runtime';\nexport { ExpressAspect } from './express.aspect';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
@@ -1,34 +1,28 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.catchErrors = void 0;
|
9
8
|
exports.errorHandle = errorHandle;
|
10
|
-
|
11
9
|
function _logger() {
|
12
10
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
|
13
|
-
|
14
11
|
_logger = function () {
|
15
12
|
return data;
|
16
13
|
};
|
17
|
-
|
18
14
|
return data;
|
19
15
|
}
|
20
|
-
|
21
|
-
|
16
|
+
const catchErrors = action => (req, res, next) =>
|
17
|
+
// TODO: @guy please take care of it
|
22
18
|
// eslint-disable-next-line promise/no-callback-in-promise
|
23
19
|
action(req, res, next).catch(error => errorHandle(error, req, res, next));
|
24
|
-
|
25
20
|
exports.catchErrors = catchErrors;
|
26
|
-
|
27
|
-
|
21
|
+
function errorHandle(err, req, res,
|
22
|
+
// TODO: Do not remove unused next, it's needed for express to catch errors!
|
28
23
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
29
24
|
next) {
|
30
25
|
_logger().default.error(`express.errorHandle, url ${req.url}, error:`, err);
|
31
|
-
|
32
26
|
err.status = err.status || 500;
|
33
27
|
res.status(err.status);
|
34
28
|
return res.jsonp({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["catchErrors","action","req","res","next","catch","error","errorHandle","err","logger","url","status","jsonp","message"],"sources":["error.ts"],"sourcesContent":["import * as express from 'express';\nimport logger from '@teambit/legacy/dist/logger/logger';\n\ninterface ResponseError {\n status?: number;\n message?: string;\n}\n\nexport const catchErrors = (action: any) => (req: express.Request, res: express.Response, next: express.NextFunction) =>\n // TODO: @guy please take care of it\n // eslint-disable-next-line promise/no-callback-in-promise\n action(req, res, next).catch((error: ResponseError) => errorHandle(error, req, res, next));\n\nexport function errorHandle(\n err: ResponseError,\n req: express.Request,\n res: express.Response,\n // TODO: Do not remove unused next, it's needed for express to catch errors!\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n next: express.NextFunction\n) {\n logger.error(`express.errorHandle, url ${req.url}, error:`, err);\n err.status = err.status || 500;\n res.status(err.status);\n return res.jsonp({\n message: err.message,\n error: err,\n });\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["catchErrors","action","req","res","next","catch","error","errorHandle","err","logger","url","status","jsonp","message"],"sources":["error.ts"],"sourcesContent":["import * as express from 'express';\nimport logger from '@teambit/legacy/dist/logger/logger';\n\ninterface ResponseError {\n status?: number;\n message?: string;\n}\n\nexport const catchErrors = (action: any) => (req: express.Request, res: express.Response, next: express.NextFunction) =>\n // TODO: @guy please take care of it\n // eslint-disable-next-line promise/no-callback-in-promise\n action(req, res, next).catch((error: ResponseError) => errorHandle(error, req, res, next));\n\nexport function errorHandle(\n err: ResponseError,\n req: express.Request,\n res: express.Response,\n // TODO: Do not remove unused next, it's needed for express to catch errors!\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n next: express.NextFunction\n) {\n logger.error(`express.errorHandle, url ${req.url}, error:`, err);\n err.status = err.status || 500;\n res.status(err.status);\n return res.jsonp({\n message: err.message,\n error: err,\n });\n}\n"],"mappings":";;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOO,MAAMA,WAAW,GAAIC,MAAW,IAAK,CAACC,GAAoB,EAAEC,GAAqB,EAAEC,IAA0B;AAClH;AACA;AACAH,MAAM,CAACC,GAAG,EAAEC,GAAG,EAAEC,IAAI,CAAC,CAACC,KAAK,CAAEC,KAAoB,IAAKC,WAAW,CAACD,KAAK,EAAEJ,GAAG,EAAEC,GAAG,EAAEC,IAAI,CAAC,CAAC;AAAC;AAEtF,SAASG,WAAW,CACzBC,GAAkB,EAClBN,GAAoB,EACpBC,GAAqB;AACrB;AACA;AACAC,IAA0B,EAC1B;EACAK,iBAAM,CAACH,KAAK,CAAE,4BAA2BJ,GAAG,CAACQ,GAAI,UAAS,EAAEF,GAAG,CAAC;EAChEA,GAAG,CAACG,MAAM,GAAGH,GAAG,CAACG,MAAM,IAAI,GAAG;EAC9BR,GAAG,CAACQ,MAAM,CAACH,GAAG,CAACG,MAAM,CAAC;EACtB,OAAOR,GAAG,CAACS,KAAK,CAAC;IACfC,OAAO,EAAEL,GAAG,CAACK,OAAO;IACpBP,KAAK,EAAEE;EACT,CAAC,CAAC;AACJ"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { catchErrors, errorHandle } from './error';\n"],"mappings":"
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { catchErrors, errorHandle } from './error';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
package/dist/types/index.js
CHANGED
@@ -39,44 +39,32 @@ Object.defineProperty(exports, "Verb", {
|
|
39
39
|
return _route().Verb;
|
40
40
|
}
|
41
41
|
});
|
42
|
-
|
43
42
|
function _request() {
|
44
43
|
const data = require("./request");
|
45
|
-
|
46
44
|
_request = function () {
|
47
45
|
return data;
|
48
46
|
};
|
49
|
-
|
50
47
|
return data;
|
51
48
|
}
|
52
|
-
|
53
49
|
function _response() {
|
54
50
|
const data = require("./response");
|
55
|
-
|
56
51
|
_response = function () {
|
57
52
|
return data;
|
58
53
|
};
|
59
|
-
|
60
54
|
return data;
|
61
55
|
}
|
62
|
-
|
63
56
|
function _next() {
|
64
57
|
const data = require("./next");
|
65
|
-
|
66
58
|
_next = function () {
|
67
59
|
return data;
|
68
60
|
};
|
69
|
-
|
70
61
|
return data;
|
71
62
|
}
|
72
|
-
|
73
63
|
function _route() {
|
74
64
|
const data = require("./route");
|
75
|
-
|
76
65
|
_route = function () {
|
77
66
|
return data;
|
78
67
|
};
|
79
|
-
|
80
68
|
return data;
|
81
69
|
}
|
82
70
|
|
package/dist/types/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { Request } from './request';\nexport { Response } from './response';\nexport { NextFunction } from './next';\nexport { Route, Middleware, Verb } from './route';\n"],"mappings":"
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { Request } from './request';\nexport { Response } from './response';\nexport { NextFunction } from './next';\nexport { Route, Middleware, Verb } from './route';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
package/dist/types/route.js
CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.Verb = void 0;
|
7
|
-
|
8
7
|
/**
|
9
8
|
* define express Middleware
|
10
9
|
*/
|
@@ -12,9 +11,7 @@ let Verb;
|
|
12
11
|
/**
|
13
12
|
* express new Route
|
14
13
|
*/
|
15
|
-
|
16
14
|
exports.Verb = Verb;
|
17
|
-
|
18
15
|
(function (Verb) {
|
19
16
|
Verb["WRITE"] = "write";
|
20
17
|
Verb["READ"] = "read";
|
package/dist/types/route.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Verb"],"sources":["route.ts"],"sourcesContent":["import { NextFunction } from './next';\nimport { Request } from './request';\nimport { Response } from './response';\n\n/**\n * define express Middleware\n */\nexport type Middleware = (req: Request, res: Response, next: NextFunction) => Promise<any>;\n\nexport enum Verb {\n WRITE = 'write',\n READ = 'read',\n}\n\n/**\n * express new Route\n */\n\nexport interface Route {\n method: string;\n route: string | RegExp;\n disableNamespace?: boolean;\n verb?: Verb;\n middlewares: Middleware[];\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["Verb"],"sources":["route.ts"],"sourcesContent":["import { NextFunction } from './next';\nimport { Request } from './request';\nimport { Response } from './response';\n\n/**\n * define express Middleware\n */\nexport type Middleware = (req: Request, res: Response, next: NextFunction) => Promise<any>;\n\nexport enum Verb {\n WRITE = 'write',\n READ = 'read',\n}\n\n/**\n * express new Route\n */\n\nexport interface Route {\n method: string;\n route: string | RegExp;\n disableNamespace?: boolean;\n verb?: Verb;\n middlewares: Middleware[];\n}\n"],"mappings":";;;;;;AAIA;AACA;AACA;AAFA,IAKYA,IAAI;AAKhB;AACA;AACA;AAFA;AAAA,WALYA,IAAI;EAAJA,IAAI;EAAJA,IAAI;AAAA,GAAJA,IAAI,oBAAJA,IAAI"}
|
Binary file
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/express",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.691",
|
4
4
|
"homepage": "https://bit.dev/teambit/harmony/express",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.harmony",
|
8
8
|
"name": "express",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.691"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"body-parser": "1.19.0",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"@babel/runtime": "7.12.18",
|
16
16
|
"core-js": "^3.0.0",
|
17
17
|
"@teambit/harmony": "0.3.3",
|
18
|
-
"@teambit/cli": "0.0.
|
19
|
-
"@teambit/logger": "0.0.
|
18
|
+
"@teambit/cli": "0.0.593",
|
19
|
+
"@teambit/logger": "0.0.686"
|
20
20
|
},
|
21
21
|
"devDependencies": {
|
22
22
|
"@types/react": "^17.0.8",
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"@types/node": "12.20.4"
|
30
30
|
},
|
31
31
|
"peerDependencies": {
|
32
|
-
"@teambit/legacy": "1.0.
|
32
|
+
"@teambit/legacy": "1.0.376",
|
33
33
|
"react-dom": "^16.8.0 || ^17.0.0",
|
34
34
|
"react": "^16.8.0 || ^17.0.0"
|
35
35
|
},
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.691/dist/express.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.691/dist/express.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
Binary file
|