Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve static assets from NP #60490

Merged
merged 24 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a3cc842
Merge branch 'master' into issue-50654-http-resources-service
mshustov Mar 18, 2020
9bb4937
add hapi.inert plugin to NP
mshustov Mar 18, 2020
aaafdc6
update tests
mshustov Mar 18, 2020
475a5c3
move serving static assets
mshustov Mar 18, 2020
6aa6e56
update tests
mshustov Mar 18, 2020
fabb201
add functional tests
mshustov Mar 18, 2020
a2394df
fix type errors. Hapi.Request doesn't support typings for payload
mshustov Mar 18, 2020
e03576a
update docs
mshustov Mar 18, 2020
05e026c
remove comment
mshustov Mar 18, 2020
0dec6ca
move assets to NP
mshustov Mar 18, 2020
048c385
update all assets references
mshustov Mar 18, 2020
70e9ffc
Merge branch 'master' into issue-50654-http-resources-service
mshustov Mar 19, 2020
dc10e99
address Spencer's comments
mshustov Mar 19, 2020
3d7dcb0
move ui settings migration to migration examples
mshustov Mar 19, 2020
862d230
document legacy plugin spec
mshustov Mar 19, 2020
d0678c9
Merge branch 'master' into issue-50654-http-resources-service
mshustov Mar 20, 2020
3021e43
move platform assets test to integration_tests
mshustov Mar 20, 2020
59759d7
address Spencer's comment p.2
mshustov Mar 20, 2020
753f2c4
try to fix type errors
mshustov Mar 20, 2020
38fb7be
Merge branch 'master' into issue-50654-http-resources-service
mshustov Mar 24, 2020
9912b9a
fix merge commit
mshustov Mar 24, 2020
30effed
Merge branch 'master' into issue-50654-http-resources-service
mshustov Mar 27, 2020
ce9fbb5
Merge branch 'master' into issue-50654-http-resources-service
mshustov Mar 27, 2020
4aad487
update tests
mshustov Mar 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,13 @@
"@types/glob": "^7.1.1",
"@types/globby": "^8.0.0",
"@types/graphql": "^0.13.2",
"@types/h2o2": "^8.1.1",
"@types/hapi": "^17.0.18",
"@types/hapi-auth-cookie": "^9.1.0",
"@types/has-ansi": "^3.0.0",
"@types/history": "^4.7.3",
"@types/hoek": "^4.1.3",
"@types/inert": "^5.1.2",
"@types/jest": "24.0.19",
"@types/joi": "^13.4.2",
"@types/jquery": "^3.3.31",
Expand Down
8 changes: 8 additions & 0 deletions packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
return null;
}

if (uri.startsWith('ui/assets')) {
return Path.resolve(
worker.repoRoot,
'src/core/server/core_app/',
uri.replace('ui/', '')
);
}

// manually force ui/* urls in legacy styles to resolve to ui/legacy/public
if (uri.startsWith('ui/') && parseDirPath(base).dirs.includes('legacy')) {
mshustov marked this conversation as resolved.
Show resolved Hide resolved
return Path.resolve(
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-storybook/storybook_config/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ const path = require('path');

// Extend the Storybook Middleware to include a route to access Legacy UI assets
module.exports = function(router) {
router.get('/ui', serve(path.resolve(__dirname, '../../../../src/legacy/ui/public/assets')));
router.get('/ui', serve(path.resolve(__dirname, '../../../src/core/server/core_app/assets')));
};
12 changes: 12 additions & 0 deletions src/core/server/core_app/core_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import Path from 'path';
import { fromRoot } from '../../../core/server/utils';

import { InternalCoreSetup } from '../internal_types';
import { CoreContext } from '../core_context';
import { Logger } from '../logging';
Expand All @@ -29,6 +32,7 @@ export class CoreApp {
setup(coreSetup: InternalCoreSetup) {
this.logger.debug('Setting up core app.');
this.registerDefaultRoutes(coreSetup);
this.registerStaticDirs(coreSetup);
}

private registerDefaultRoutes(coreSetup: InternalCoreSetup) {
Expand All @@ -49,4 +53,12 @@ export class CoreApp {
res.ok({ body: { version: '0.0.1' } })
);
}
private registerStaticDirs(coreSetup: InternalCoreSetup) {
coreSetup.http.registerStaticDir('/ui/{path*}', Path.resolve(__dirname, './assets'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to the other options. we can place them under src/core/server/assets, for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR doesn't yet expose this to plugins directly, but I wonder if there's really any value into allowing/requiring plugins to add the {path*} part of the path string. Should we do this for them automatically?

I think that if there is a real use case to only serving files of a certain directory depth, this should be exposed more explicitly via an option to registerStaticDir:

registerStaticDir({
  path: '/ui/',
  directory: Path.resolve(__dirname, './assets',
  depth: 3 // accepts positive integers, defaults to `Infinity`
})

Can be dealt with in PR that exposes to plugins. Just wanted to note while I thought about it. Also if there's no current need to specify the depth we probably don't need this option at all and should just automatically append the /{path*} when we register the route with Hapi.

Copy link
Contributor Author

@mshustov mshustov Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be dealt with in PR that exposes to plugins.

I don't think we should expose this API directly to the plugins. Otherwise, any plugin can expose an arbitrary folder (config folder with kibana.yml, for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We expose /public directory in the LP automatically:

getPublicDir() {
if (this._publicDir === false) {
return null;
}
if (!this._publicDir) {
return resolve(this.getPack().getPath(), 'public');
}
return this._publicDir;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should expose this API directly to the plugins. Otherwise, any plugin can expose an arbitrary folder (config folder with kibana.yml, for example)

We could have an API to only allow to serve from within the plugin's base folder. That would avoid the risk of exposing files from outside their folder.

i.e

// src/core/plugins/my_plugin/server/plugin.ts
coreSetup.http.registerStaticDir('/my-plugin-data/{path*}', 'my_assets_folder');

that would serve the src/core/plugins/my_plugin/my_assets_folder (or maybe src/core/plugins/my_plugin/server/my_assets_folder, need to decide)

I know this PR doesn't yet expose this to plugins directly, but I wonder if there's really any value into allowing/requiring plugins to add the {path*}

I agree, that doesn't seems necessary imho

Previous proposal example should probably be

coreSetup.http.registerStaticDir('/my-plugin-data', 'my_assets_folder');

I think that if there is a real use case to only serving files of a certain directory depth, this should be exposed more explicitly via an option to registerStaticDir

Don't really see any obvious need for that. KISS imho.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need to expose to plugins, then as-is is good with me 👍


coreSetup.http.registerStaticDir(
'/node_modules/@kbn/ui-framework/dist/{path*}',
fromRoot('node_modules/@kbn/ui-framework/dist')
);
Comment on lines +59 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. We sure were doing fun things.

}
}
25 changes: 14 additions & 11 deletions src/core/server/http/base_path_proxy_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Agent as HttpsAgent, ServerOptions as TlsOptions } from 'https';
import apm from 'elastic-apm-node';
import { ByteSizeValue } from '@kbn/config-schema';
import { Server, Request, ResponseToolkit } from 'hapi';
import HapiProxy from 'h2o2';
import { sample } from 'lodash';
import BrowserslistUserAgent from 'browserslist-useragent';
import * as Rx from 'rxjs';
Expand Down Expand Up @@ -102,7 +103,7 @@ export class BasePathProxyServer {

// Register hapi plugin that adds proxying functionality. It can be configured
// through the route configuration object (see { handler: { proxy: ... } }).
await this.server.register({ plugin: require('h2o2') });
await this.server.register([HapiProxy]);

if (this.httpConfig.ssl.enabled) {
const tlsOptions = serverOptions.tls as TlsOptions;
Expand Down Expand Up @@ -166,7 +167,8 @@ export class BasePathProxyServer {
host: this.server.info.host,
passThrough: true,
port: this.devConfig.basePathProxyTargetPort,
protocol: this.server.info.protocol,
// typings mismatch. h2o2 doesn't support "socket"
protocol: this.server.info.protocol as HapiProxy.ProxyHandlerOptions['protocol'],
xforward: true,
},
},
Expand Down Expand Up @@ -195,16 +197,17 @@ export class BasePathProxyServer {
agent: this.httpsAgent,
passThrough: true,
xforward: true,
mapUri: (request: Request) => ({
mshustov marked this conversation as resolved.
Show resolved Hide resolved
uri: Url.format({
hostname: request.server.info.host,
port: this.devConfig.basePathProxyTargetPort,
protocol: request.server.info.protocol,
pathname: `${this.httpConfig.basePath}/${request.params.kbnPath}`,
query: request.query,
mapUri: (request: Request) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed type errors

Promise.resolve({
uri: Url.format({
hostname: request.server.info.host,
port: this.devConfig.basePathProxyTargetPort,
protocol: request.server.info.protocol,
pathname: `${this.httpConfig.basePath}/${request.params.kbnPath}`,
query: request.query,
}),
headers: request.headers,
}),
headers: request.headers,
}),
},
},
method: '*',
Expand Down
25 changes: 24 additions & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { Server } from 'hapi';
import HapiStaticFiles from 'inert';
import url from 'url';

import { Logger, LoggerFactory } from '../logging';
Expand Down Expand Up @@ -44,6 +45,7 @@ export interface HttpServerSetup {
* @param router {@link IRouter} - a router with registered route handlers.
*/
registerRouter: (router: IRouter) => void;
registerStaticDir: (path: string, dirPath: string) => void;
basePath: HttpServiceSetup['basePath'];
csp: HttpServiceSetup['csp'];
createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];
Expand Down Expand Up @@ -97,10 +99,11 @@ export class HttpServer {
this.registeredRouters.add(router);
}

public setup(config: HttpConfig): HttpServerSetup {
public async setup(config: HttpConfig): Promise<HttpServerSetup> {
const serverOptions = getServerOptions(config);
const listenerOptions = getListenerOptions(config);
this.server = createServer(serverOptions, listenerOptions);
await this.server.register([HapiStaticFiles]);
joshdover marked this conversation as resolved.
Show resolved Hide resolved
this.config = config;

const basePathService = new BasePath(config.basePath);
Expand All @@ -109,6 +112,7 @@ export class HttpServer {

return {
registerRouter: this.registerRouter.bind(this),
registerStaticDir: this.registerStaticDir.bind(this),
registerOnPreAuth: this.registerOnPreAuth.bind(this),
registerOnPostAuth: this.registerOnPostAuth.bind(this),
registerOnPreResponse: this.registerOnPreResponse.bind(this),
Expand Down Expand Up @@ -339,4 +343,23 @@ export class HttpServer {
return t.next({ headers: authResponseHeaders });
});
}

private registerStaticDir(path: string, dirPath: string) {
if (this.server === undefined) {
throw new Error('Http server is not setup up yet');
}

this.server.route({
path,
method: 'GET',
handler: {
directory: {
path: dirPath,
listing: false,
lookupCompressed: true,
mshustov marked this conversation as resolved.
Show resolved Hide resolved
},
},
options: { auth: false },
});
}
}
1 change: 1 addition & 0 deletions src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const createSetupContractMock = () => {
registerRouteHandlerContext: jest.fn(),
registerOnPreResponse: jest.fn(),
createRouter: jest.fn().mockImplementation(() => mockRouter.create({})),
registerStaticDir: jest.fn(),
basePath: createBasePathMock(),
csp: CspConfig.DEFAULT,
auth: createAuthMock(),
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/http/http_tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

jest.mock('fs', () => ({
// Hapi Inert patches native methods
joshdover marked this conversation as resolved.
Show resolved Hide resolved
...jest.requireActual('fs'),
readFileSync: jest.fn(),
}));

Expand Down
1 change: 1 addition & 0 deletions src/core/server/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export interface InternalHttpServiceSetup
auth: HttpServerSetup['auth'];
server: HttpServerSetup['server'];
createRouter: (path: string, plugin?: PluginOpaqueId) => IRouter;
registerStaticDir: (path: string, dirPath: string) => void;
getAuthHeaders: GetAuthHeaders;
registerRouteHandlerContext: <T extends keyof RequestHandlerContext>(
pluginOpaqueId: PluginOpaqueId,
Expand Down
10 changes: 9 additions & 1 deletion src/core/server/legacy/legacy_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ beforeEach(() => {
contracts: new Map([['plugin-id', 'plugin-value']]),
uiPlugins: {
public: new Map([['plugin-id', {} as DiscoveredPlugin]]),
internal: new Map([['plugin-id', { publicTargetDir: 'path/to/target/public' }]]),
internal: new Map([
[
'plugin-id',
{
publicTargetDir: 'path/to/target/public',
publicAssetsDir: '/plugins/name/assets/',
},
],
]),
browserConfigs: new Map(),
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ export class LegacyService implements CoreService {
plugins: startDeps.plugins,
},
__internals: {
http: {
registerStaticDir: setupDeps.core.http.registerStaticDir,
},
hapiServer: setupDeps.core.http.server,
kibanaMigrator: startDeps.core.savedObjects.migrator,
uiPlugins: setupDeps.core.plugins.uiPlugins,
Expand Down
4 changes: 3 additions & 1 deletion src/core/server/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,15 @@ describe('PluginsService', () => {
config$.next({ plugins: { initialize: true }, plugin1: { enabled: false } });

await pluginsService.discover();
const { uiPlugins } = await pluginsService.setup({} as any);
const { uiPlugins } = await pluginsService.setup(setupDeps);
expect(uiPlugins.internal).toMatchInlineSnapshot(`
Map {
"plugin-1" => Object {
"publicAssetsDir": <absolute path>/path-1/public/assets,
"publicTargetDir": <absolute path>/path-1/target/public,
},
"plugin-2" => Object {
"publicAssetsDir": <absolute path>/path-2/public/assets,
"publicTargetDir": <absolute path>/path-2/target/public,
},
}
Expand Down
11 changes: 11 additions & 0 deletions src/core/server/plugins/plugins_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
this.log.info('Plugin initialization disabled.');
} else {
contracts = await this.pluginsSystem.setupPlugins(deps);
this.registerPluginStaticDirs(deps);
}

const uiPlugins = this.pluginsSystem.uiPlugins();
Expand Down Expand Up @@ -217,6 +218,7 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
if (plugin.includesUiPlugin) {
this.uiPluginInternalInfo.set(plugin.name, {
publicTargetDir: Path.resolve(plugin.path, 'target/public'),
publicAssetsDir: Path.resolve(plugin.path, 'public/assets'),
Copy link
Contributor Author

@mshustov mshustov Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
}

Expand Down Expand Up @@ -256,4 +258,13 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
)
);
}

private registerPluginStaticDirs(deps: PluginsServiceSetupDeps) {
for (const [pluginName, pluginInfo] of this.uiPluginInternalInfo) {
deps.http.registerStaticDir(
`/plugins/${pluginName}/assets/{path*}`,
pluginInfo.publicAssetsDir
);
Comment on lines +270 to +273
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we document this feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added docs to the migration guide. Let me know if I can improve something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a temporary measure to allow plugins to move their static assets to NP plugins until #50654 lands? Didn't we want to make all assets exposition explicit? Or is this going to be permanent to allow client-only plugins to expose assets?

Copy link
Contributor Author

@mshustov mshustov Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we want to make all assets exposition explicit?

I'm on the fence here. On the one hand, we prefer explicitness, but it increases the API surface, makes a folder structure less predictable, enforces server-side plugin usage.
If we decide to add explicit API, it would be something locked within the plugin folder. As you proposed in #60490 (comment)

}
}
}
4 changes: 4 additions & 0 deletions src/core/server/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export interface InternalPluginInfo {
* served
*/
readonly publicTargetDir: string;
/**
* Path to the plugin assets directory.
*/
readonly publicAssetsDir: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to server build artifacts from the /assets folder, so I separated them.

}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,8 @@ export const validBodyOutput: readonly ["data", "stream"];
// src/core/server/legacy/types.ts:165:3 - (ae-forgotten-export) The symbol "LegacyAppSpec" needs to be exported by the entry point index.d.ts
// src/core/server/legacy/types.ts:166:16 - (ae-forgotten-export) The symbol "LegacyPluginSpec" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/plugins_service.ts:44:5 - (ae-forgotten-export) The symbol "InternalPluginInfo" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/types.ts:226:3 - (ae-forgotten-export) The symbol "KibanaConfigType" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/types.ts:226:3 - (ae-forgotten-export) The symbol "SharedGlobalConfigKeys" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/types.ts:228:3 - (ae-forgotten-export) The symbol "PathConfigType" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/types.ts:230:3 - (ae-forgotten-export) The symbol "KibanaConfigType" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/types.ts:230:3 - (ae-forgotten-export) The symbol "SharedGlobalConfigKeys" needs to be exported by the entry point index.d.ts
// src/core/server/plugins/types.ts:232:3 - (ae-forgotten-export) The symbol "PathConfigType" needs to be exported by the entry point index.d.ts

```
26 changes: 13 additions & 13 deletions src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const IGNORE_FILE_GLOBS = [
'**/.*',
'**/{webpackShims,__mocks__}/**/*',
'x-pack/docs/**/*',
'src/legacy/ui/public/assets/fonts/**/*',
'src/core/server/core_app/assets/fonts/**/*',
'packages/kbn-utility-types/test-d/**/*',
'**/Jenkinsfile*',
'Dockerfile*',
Expand Down Expand Up @@ -123,18 +123,18 @@ export const TEMPORARILY_IGNORED_PATHS = [
'src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js',
'src/fixtures/config_upgrade_from_4.0.0_to_4.0.1-snapshot.json',
'src/legacy/core_plugins/vis_type_vislib/public/vislib/__tests__/lib/fixtures/mock_data/terms/_seriesMultiple.js',
'src/legacy/ui/public/assets/favicons/android-chrome-192x192.png',
'src/legacy/ui/public/assets/favicons/android-chrome-256x256.png',
'src/legacy/ui/public/assets/favicons/android-chrome-512x512.png',
'src/legacy/ui/public/assets/favicons/apple-touch-icon.png',
'src/legacy/ui/public/assets/favicons/favicon-16x16.png',
'src/legacy/ui/public/assets/favicons/favicon-32x32.png',
'src/legacy/ui/public/assets/favicons/mstile-70x70.png',
'src/legacy/ui/public/assets/favicons/mstile-144x144.png',
'src/legacy/ui/public/assets/favicons/mstile-150x150.png',
'src/legacy/ui/public/assets/favicons/mstile-310x150.png',
'src/legacy/ui/public/assets/favicons/mstile-310x310.png',
'src/legacy/ui/public/assets/favicons/safari-pinned-tab.svg',
'src/core/server/core_app/assets/favicons/android-chrome-192x192.png',
'src/core/server/core_app/assets/favicons/android-chrome-256x256.png',
'src/core/server/core_app/assets/favicons/android-chrome-512x512.png',
'src/core/server/core_app/assets/favicons/apple-touch-icon.png',
'src/core/server/core_app/assets/favicons/favicon-16x16.png',
'src/core/server/core_app/assets/favicons/favicon-32x32.png',
'src/core/server/core_app/assets/favicons/mstile-70x70.png',
'src/core/server/core_app/assets/favicons/mstile-144x144.png',
'src/core/server/core_app/assets/favicons/mstile-150x150.png',
'src/core/server/core_app/assets/favicons/mstile-310x150.png',
'src/core/server/core_app/assets/favicons/mstile-310x310.png',
'src/core/server/core_app/assets/favicons/safari-pinned-tab.svg',
'src/legacy/ui/public/styles/bootstrap/component-animations.less',
'src/legacy/ui/public/styles/bootstrap/input-groups.less',
'src/legacy/ui/public/styles/bootstrap/list-group.less',
Expand Down
20 changes: 0 additions & 20 deletions src/legacy/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { format } from 'url';
import { resolve } from 'path';
import _ from 'lodash';
import Boom from 'boom';

Expand All @@ -32,22 +31,6 @@ export default async function(kbnServer, server, config) {

await registerHapiPlugins(server);

// provide a simple way to expose static directories
server.decorate('server', 'exposeStaticDir', function(routePath, dirPath) {
this.route({
path: routePath,
method: 'GET',
handler: {
directory: {
path: dirPath,
listing: false,
lookupCompressed: true,
},
},
config: { auth: false },
});
});

// helper for creating view managers for servers
server.decorate('server', 'setupViews', function(path, engines) {
this.views({
Expand Down Expand Up @@ -77,7 +60,4 @@ export default async function(kbnServer, server, config) {
.permanent(true);
},
});

// Expose static assets
server.exposeStaticDir('/ui/{path*}', resolve(__dirname, '../../ui/public/assets'));
}
5 changes: 4 additions & 1 deletion src/legacy/server/plugins/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export class Plugin {
});

if (this.publicDir) {
server.exposeStaticDir(`/plugins/${id}/{path*}`, this.publicDir);
server.newPlatform.__internals.http.registerStaticDir(
`/plugins/${id}/{path*}`,
this.publicDir
);
}

// Many of the plugins are simply adding static assets to the server and we don't need
Expand Down
Loading