Skip to content

Commit

Permalink
[HTTP] Update plugin static asset registration to preserve legacy beh…
Browse files Browse the repository at this point in the history
…aviour (elastic#179523)
  • Loading branch information
jloleysens authored Mar 27, 2024
1 parent 7391431 commit fc17526
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 18 additions & 3 deletions packages/core/apps/core-apps-server-internal/src/core_app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ describe('CoreApp', () => {
});
});

it('registers expected static dirs if there are public plugins', async () => {
it('registers expected static dirs for all plugins with static dirs', async () => {
const uiPlugins = emptyPlugins();
uiPlugins.public.set('some-plugin', {
type: PluginType.preboot,
Expand Down Expand Up @@ -348,6 +348,12 @@ describe('CoreApp', () => {
requiredBundles: [],
version: '1.0.0',
});
uiPlugins.internal.set('some-plugin-3-internal', {
publicAssetsDir: '/foo-internal',
publicTargetDir: '/bar-internal',
requiredBundles: [],
version: '1.0.0',
});

internalCoreSetup.http.staticAssets.prependServerPath.mockReturnValue('/static-assets-path');
internalCoreSetup.http.staticAssets.getPluginServerPath.mockImplementation(
Expand All @@ -356,8 +362,8 @@ describe('CoreApp', () => {
await coreApp.setup(internalCoreSetup, uiPlugins);

expect(internalCoreSetup.http.registerStaticDir).toHaveBeenCalledTimes(
// Twice for all UI plugins + core's UI asset routes
uiPlugins.public.size * 2 + 2
// Twice for all _internal_ UI plugins + core's UI asset routes
uiPlugins.internal.size * 2 + 2
);
expect(internalCoreSetup.http.registerStaticDir).toHaveBeenCalledWith(
'/static-assets-path',
Expand All @@ -383,5 +389,14 @@ describe('CoreApp', () => {
'/plugins/some-plugin-2/assets/{path*}', // legacy
expect.any(String)
);

expect(internalCoreSetup.http.registerStaticDir).toHaveBeenCalledWith(
'/static-assets-path/some-plugin-3-internal/{path*}',
expect.any(String)
);
expect(internalCoreSetup.http.registerStaticDir).toHaveBeenCalledWith(
'/plugins/some-plugin-3-internal/assets/{path*}', // legacy
expect.any(String)
);
});
});
5 changes: 2 additions & 3 deletions packages/core/apps/core-apps-server-internal/src/core_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,8 @@ export class CoreAppsService {
);
});

for (const [pluginName] of uiPlugins.public) {
const pluginInfo = uiPlugins.internal.get(pluginName);
if (!pluginInfo) continue; // assuming we will never hit this case; a public entry should have internal info registered
for (const [pluginName, pluginInfo] of uiPlugins.internal) {
if (!pluginInfo.publicAssetsDir) continue;
/**
* Serve UI from sha-scoped and not-sha-scoped paths to allow time for plugin code to migrate
* Eventually we only want to serve from the sha scoped path
Expand Down

0 comments on commit fc17526

Please sign in to comment.