@teambit/express 0.0.695 → 0.0.697

Sign up to get free protection for your applications and to get access to all the features.
@@ -131,6 +131,7 @@ class ExpressMain {
131
131
  method: 'get',
132
132
  path: '/_health',
133
133
  disableNamespace: false,
134
+ priority: 0,
134
135
  middlewares: [async (req, res) => res.send('ok')]
135
136
  }];
136
137
  }
@@ -138,6 +139,7 @@ class ExpressMain {
138
139
  const internalRoutes = this.createRootRoutes();
139
140
  const routes = this.createRoutes();
140
141
  const allRoutes = (0, _lodash().concat)(routes, internalRoutes);
142
+ const sortedRoutes = (0, _lodash().sortBy)(allRoutes, r => r.priority).reverse();
141
143
  const app = expressApp || (0, _express().default)();
142
144
  app.use((req, res, next) => {
143
145
  if (this.config.loggerIgnorePath.includes(req.url)) return next();
@@ -146,7 +148,7 @@ class ExpressMain {
146
148
  });
147
149
  if (!(options !== null && options !== void 0 && options.disableBodyParser)) this.bodyParser(app);
148
150
  this.middlewareSlot.toArray().flatMap(([, middlewares]) => middlewares.flatMap(middlewareManifest => app.use(middlewareManifest.middleware)));
149
- allRoutes.forEach(routeInfo => {
151
+ sortedRoutes.forEach(routeInfo => {
150
152
  const {
151
153
  method,
152
154
  path,
@@ -168,7 +170,8 @@ class ExpressMain {
168
170
  method: (0, _lodash().lowerCase)(route.method),
169
171
  path: route.route,
170
172
  disableNamespace: route.disableNamespace,
171
- middlewares
173
+ middlewares,
174
+ priority: route.priority || 0
172
175
  };
173
176
  });
174
177
  });
@@ -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,WAAW,CAAC;EAGvBC,WAAW;EACT;AACJ;AACA;EACaC,MAAqB;EAE9B;AACJ;AACA;EACYC,UAAqB;EAE7B;AACJ;AACA;EACaC,MAAc,EAEdC,cAA8B,EACvC;IAAA,KAbSH,MAAqB,GAArBA,MAAqB;IAAA,KAKtBC,UAAqB,GAArBA,UAAqB;IAAA,KAKpBC,MAAc,GAAdA,MAAc;IAAA,KAEdC,cAA8B,GAA9BA,cAA8B;EACtC;;EAEH;AACF;AACA;EACE,MAAMC,MAAM,CAACC,IAAa,EAAE;IAC1B,MAAMC,UAAU,GAAGD,IAAI,IAAI,IAAI,CAACL,MAAM,CAACK,IAAI;IAC3C,MAAME,GAAG,GAAG,IAAI,CAACC,SAAS,EAAE;IAC5BD,GAAG,CAACH,MAAM,CAACE,UAAU,CAAC;EACxB;;EAEA;AACF;AACA;AACA;EACEG,QAAQ,CAACC,MAAe,EAAE;IACxB,IAAI,CAACT,UAAU,CAACQ,QAAQ,CAACC,MAAM,CAAC;IAChC,OAAO,IAAI;EACb;;EAEA;AACF;AACA;EACEC,kBAAkB,CAACC,WAAiC,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CA9HrEzE,WAAW,kBA+HA,CAAC0E,sBAAY,CAAC;AAAA,gCA/HzB1E,WAAW,mBAiIC;EACrBO,IAAI,EAAE,IAAI;EACVS,SAAS,EAAE,KAAK;EAChBkB,gBAAgB,EAAE,CAAC,cAAc;AACnC,CAAC;AAYHjB,yBAAa,CAAC0D,UAAU,CAAC3E,WAAW,CAAC"}
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","priority","req","res","send","expressApp","options","internalRoutes","createRoutes","allRoutes","concat","sortedRoutes","sortBy","r","reverse","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, sortBy } 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 priority: 0,\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 sortedRoutes = sortBy(allRoutes, (r) => r.priority).reverse();\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 sortedRoutes.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 priority: route.priority || 0,\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,WAAW,CAAC;EAGvBC,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E;IACf,CAAC;EACH;EAEQc,sBAAsB,CAACtC,WAAyB,EAAE;IACxD,OAAOA,WAAW,CAACyC,GAAG,CAAEN,UAAU,IAAK,IAAAkB,0BAAW,EAAClB,UAAU,CAAC,CAAC;EACjE;EAEQJ,UAAU,CAACpC,GAAY,EAAE;IAC/BA,GAAG,CAAC4B,GAAG,CAACQ,qBAAU,CAACuB,IAAI,CAAC;MAAEC,KAAK,EAAE;IAAS,CAAC,CAAC,CAAC;IAC7C5D,GAAG,CAAC4B,GAAG,CAACQ,qBAAU,CAACyB,GAAG,CAAC;MAAEC,IAAI,EAAE,0BAA0B;MAAEF,KAAK,EAAE;IAAS,CAAC,CAAC,CAAC;EAChF;EAWA,aAAaG,QAAQ,CACnB,CAACC,aAAa,CAAe,EAC7BvE,MAAqB,EACrB,CAACwE,SAAS,EAAErE,cAAc,CAA8B,EACxD;IACA,MAAMD,MAAM,GAAGqE,aAAa,CAACE,YAAY,CAAC1D,yBAAa,CAACC,EAAE,CAAC;IAC3D,OAAO,IAAIlB,WAAW,CAACE,MAAM,EAAEwE,SAAS,EAAEtE,MAAM,EAAEC,cAAc,CAAC;EACnE;AACF;AAAC;AAAA,gCAlJYL,WAAW,aACL4E,kBAAW;AAAA,gCADjB5E,WAAW,WAiIP,CAAC6E,eAAI,CAACC,QAAQ,EAAW,EAAED,eAAI,CAACC,QAAQ,EAAwB,CAAC;AAAA,gCAjIrE9E,WAAW,kBAkIA,CAAC+E,sBAAY,CAAC;AAAA,gCAlIzB/E,WAAW,mBAoIC;EACrBO,IAAI,EAAE,IAAI;EACVS,SAAS,EAAE,KAAK;EAChBuB,gBAAgB,EAAE,CAAC,cAAc;AACnC,CAAC;AAYHtB,yBAAa,CAAC+D,UAAU,CAAChF,WAAW,CAAC"}
@@ -19,4 +19,6 @@ export interface Route {
19
19
  disableNamespace?: boolean;
20
20
  verb?: Verb;
21
21
  middlewares: Middleware[];
22
+ /** route priority if 2 route with the same name default is 0 */
23
+ priority?: number;
22
24
  }
@@ -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":";;;;;;AAIA;AACA;AACA;AAFA,IAKYA,IAAI;AAKhB;AACA;AACA;AAFA;AAAA,WALYA,IAAI;EAAJA,IAAI;EAAJA,IAAI;AAAA,GAAJA,IAAI,oBAAJA,IAAI"}
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 /** route priority if 2 route with the same name default is 0 */\n priority?: number;\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"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/express",
3
- "version": "0.0.695",
3
+ "version": "0.0.697",
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.695"
9
+ "version": "0.0.697"
10
10
  },
11
11
  "dependencies": {
12
12
  "body-parser": "1.19.0",
@@ -15,8 +15,8 @@
15
15
  "@babel/runtime": "7.20.0",
16
16
  "core-js": "^3.0.0",
17
17
  "@teambit/harmony": "0.3.3",
18
- "@teambit/cli": "0.0.597",
19
- "@teambit/logger": "0.0.690"
18
+ "@teambit/cli": "0.0.599",
19
+ "@teambit/logger": "0.0.692"
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.380",
32
+ "@teambit/legacy": "1.0.382",
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.695/dist/express.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.695/dist/express.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.697/dist/express.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_express@0.0.697/dist/express.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/types/route.ts CHANGED
@@ -22,4 +22,6 @@ export interface Route {
22
22
  disableNamespace?: boolean;
23
23
  verb?: Verb;
24
24
  middlewares: Middleware[];
25
+ /** route priority if 2 route with the same name default is 0 */
26
+ priority?: number;
25
27
  }