|
6 | 6 | * Side Public License, v 1. |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { join } from 'path'; |
10 | | - |
11 | | -import * as UiSharedDeps from '@kbn/ui-shared-deps'; |
12 | 9 | import { schema } from '@kbn/config-schema'; |
13 | | -import { PackageInfo } from '@kbn/config'; |
14 | | - |
15 | | -import { fromRoot } from '../../utils'; |
16 | 10 | import { IRouter } from '../../http'; |
17 | | -import { UiPlugins } from '../../plugins'; |
18 | 11 | import { createDynamicAssetHandler } from './dynamic_asset_response'; |
19 | 12 | import { FileHashCache } from './file_hash_cache'; |
20 | 13 |
|
21 | | -/** |
22 | | - * Creates the routes that serves files from `bundlesPath`. |
23 | | - * |
24 | | - * @param {Object} options |
25 | | - * @property {Array<{id,path}>} options.npUiPluginPublicDirs array of ids and paths that should be served for new platform plugins |
26 | | - * @property {string} options.regularBundlesPath |
27 | | - * @property {string} options.basePublicPath |
28 | | - * |
29 | | - * @return Array.of({Hapi.Route}) |
30 | | - */ |
31 | | -export function registerBundleRoutes({ |
32 | | - router, |
33 | | - serverBasePath, // serverBasePath |
34 | | - uiPlugins, |
35 | | - packageInfo, |
36 | | -}: { |
37 | | - router: IRouter; |
38 | | - serverBasePath: string; |
39 | | - uiPlugins: UiPlugins; |
40 | | - packageInfo: PackageInfo; |
41 | | -}) { |
42 | | - const { dist: isDist, buildNum } = packageInfo; |
43 | | - // rather than calculate the fileHash on every request, we |
44 | | - // provide a cache object to `resolveDynamicAssetResponse()` that |
45 | | - // will store the 100 most recently used hashes. |
46 | | - const fileHashCache = new FileHashCache(); |
47 | | - |
48 | | - registerRouteForBundle(router, { |
49 | | - publicPath: `${serverBasePath}/${buildNum}/bundles/kbn-ui-shared-deps/`, |
50 | | - routePath: `/${buildNum}/bundles/kbn-ui-shared-deps/`, |
51 | | - bundlesPath: UiSharedDeps.distDir, |
52 | | - fileHashCache, |
53 | | - isDist, |
54 | | - }); |
55 | | - registerRouteForBundle(router, { |
56 | | - publicPath: `${serverBasePath}/${buildNum}/bundles/core/`, |
57 | | - routePath: `/${buildNum}/bundles/core/`, |
58 | | - bundlesPath: fromRoot(join('src', 'core', 'target', 'public')), |
59 | | - fileHashCache, |
60 | | - isDist, |
61 | | - }); |
62 | | - |
63 | | - [...uiPlugins.internal.entries()].forEach(([id, { publicTargetDir }]) => { |
64 | | - registerRouteForBundle(router, { |
65 | | - publicPath: `${serverBasePath}/${buildNum}/bundles/plugin/${id}/`, |
66 | | - routePath: `/${buildNum}/bundles/plugin/${id}/`, |
67 | | - bundlesPath: publicTargetDir, |
68 | | - fileHashCache, |
69 | | - isDist, |
70 | | - }); |
71 | | - }); |
72 | | -} |
73 | | - |
74 | | -function registerRouteForBundle( |
| 14 | +export function registerRouteForBundle( |
75 | 15 | router: IRouter, |
76 | 16 | { |
77 | 17 | publicPath, |
|
0 commit comments