MCPcopy
hub / github.com/browserless/browserless / getRouteFiles

Function getRouteFiles

src/utils.ts:432–479  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

430};
431
432export const getRouteFiles = async (config: Config): Promise<string[][]> => {
433 const routes = config.getRoutes();
434 const foundRoutes: string[] = await fs
435 .readdir(routes)
436 .then((dirs) =>
437 dirs.flatMap((d) => [
438 path.join(routes, d, 'ws'),
439 path.join(routes, d, 'http'),
440 ]),
441 )
442 .catch(() => []);
443
444 const [httpRouteFolders, wsRouteFolders] = foundRoutes.reduce(
445 ([http, ws]: [string[], string[]], routePath) => {
446 if (routePath.endsWith('http')) {
447 http.push(routePath);
448 }
449
450 if (routePath.endsWith('ws')) {
451 ws.push(routePath);
452 }
453
454 return [http, ws];
455 },
456 [[], []],
457 );
458
459 const [httpDirs, wsDirs] = await Promise.all([
460 await Promise.all(
461 httpRouteFolders.map((r) =>
462 fs
463 .readdir(r)
464 .then((files) => files.map((f) => path.join(r, f)))
465 .catch(() => []),
466 ),
467 ),
468 await Promise.all(
469 wsRouteFolders.map((r) =>
470 fs
471 .readdir(r)
472 .then((files) => files.map((f) => path.join(r, f)))
473 .catch(() => []),
474 ),
475 ),
476 ]);
477
478 return [httpDirs.flat(), wsDirs.flat()];
479};
480
481export const make404 = (...messages: string[]): string => {
482 const [title, ...rest] = messages;

Callers 3

startMethod · 0.85
buildOpenAPIFunction · 0.85
buildSchemasFunction · 0.85

Calls 1

getRoutesMethod · 0.80

Tested by

no test coverage detected