-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
mshustov
merged 24 commits into
elastic:master
from
mshustov:issue-50654-http-resources-service
Mar 27, 2020
Merged
Serve static assets from NP #60490
Changes from all 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 9bb4937
add hapi.inert plugin to NP
mshustov aaafdc6
update tests
mshustov 475a5c3
move serving static assets
mshustov 6aa6e56
update tests
mshustov fabb201
add functional tests
mshustov a2394df
fix type errors. Hapi.Request doesn't support typings for payload
mshustov e03576a
update docs
mshustov 05e026c
remove comment
mshustov 0dec6ca
move assets to NP
mshustov 048c385
update all assets references
mshustov 70e9ffc
Merge branch 'master' into issue-50654-http-resources-service
mshustov dc10e99
address Spencer's comments
mshustov 3d7dcb0
move ui settings migration to migration examples
mshustov 862d230
document legacy plugin spec
mshustov d0678c9
Merge branch 'master' into issue-50654-http-resources-service
mshustov 3021e43
move platform assets test to integration_tests
mshustov 59759d7
address Spencer's comment p.2
mshustov 753f2c4
try to fix type errors
mshustov 38fb7be
Merge branch 'master' into issue-50654-http-resources-service
mshustov 9912b9a
fix merge commit
mshustov 30effed
Merge branch 'master' into issue-50654-http-resources-service
mshustov ce9fbb5
Merge branch 'master' into issue-50654-http-resources-service
mshustov 4aad487
update tests
mshustov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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) { | ||
|
@@ -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')); | ||
|
||
coreSetup.http.registerStaticDir( | ||
'/node_modules/@kbn/ui-framework/dist/{path*}', | ||
fromRoot('node_modules/@kbn/ui-framework/dist') | ||
); | ||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow. We sure were doing fun things. |
||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/core/server/core_app/integration_tests/static_assets.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import * as kbnTestServer from '../../../../test_utils/kbn_server'; | ||
import { Root } from '../../root'; | ||
|
||
describe('Platform assets', function() { | ||
let root: Root; | ||
|
||
beforeAll(async function() { | ||
root = kbnTestServer.createRoot(); | ||
|
||
await root.setup(); | ||
await root.start(); | ||
}); | ||
|
||
afterAll(async function() { | ||
await root.shutdown(); | ||
}); | ||
|
||
it('exposes static assets', async () => { | ||
await kbnTestServer.request.get(root, '/ui/favicons/favicon.ico').expect(200); | ||
}); | ||
|
||
it('returns 404 if not found', async function() { | ||
await kbnTestServer.request.get(root, '/ui/favicons/not-a-favicon.ico').expect(404); | ||
}); | ||
|
||
it('does not expose folder content', async function() { | ||
await kbnTestServer.request.get(root, '/ui/favicons/').expect(403); | ||
}); | ||
|
||
it('does not allow file tree traversing', async function() { | ||
await kbnTestServer.request.get(root, '/ui/../../../../../README.md').expect(404); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
: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.There was a problem hiding this comment.
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)There was a problem hiding this comment.
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:kibana/src/legacy/plugin_discovery/plugin_spec/plugin_spec.js
Lines 164 to 174 in 85c8232
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
that would serve the
src/core/plugins/my_plugin/my_assets_folder
(or maybesrc/core/plugins/my_plugin/server/my_assets_folder
, need to decide)I agree, that doesn't seems necessary imho
Previous proposal example should probably be
Don't really see any obvious need for that. KISS imho.
There was a problem hiding this comment.
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 👍