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

Add ComponentResourceHandler to server #3284

Merged
merged 13 commits into from
Mar 31, 2022
Merged

Add ComponentResourceHandler to server #3284

merged 13 commits into from
Mar 31, 2022

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 30, 2022

This PR implements a so called ComponentResourceHandler that is always added to the server. The ComponentResourceHandler resolves paths relative to some module, i.e. it resolves patterns like <endpoint>/<module>/<class>/<attribute>/<path_to_resource>. Internally the resource handler then resolves the path to the module that was referenced, the class that was referenced and finally the attribute on that class. If and only if the requested resource is listed in that attribute will it resolve the path_to_resource and serve it. This means that ReactiveHTML and Template resources that reference local files can now be resolved correctly without having to be bundled into the Panel bundle itself.

Fixes #3241
Fixes #1787

Partially addresses #2903

  • Add tests
  • Fix security issues (you can only access static files which were explicitly referenced)

@philippjfr philippjfr changed the title Add ModuleResourceHandler to server Add ComponentResourceHandler to server Mar 30, 2022
@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #3284 (b80f01f) into master (0c4408b) will increase coverage by 0.01%.
The diff coverage is 79.00%.

@@            Coverage Diff             @@
##           master    #3284      +/-   ##
==========================================
+ Coverage   83.29%   83.30%   +0.01%     
==========================================
  Files         195      195              
  Lines       26166    26325     +159     
==========================================
+ Hits        21795    21931     +136     
- Misses       4371     4394      +23     
Impacted Files Coverage Δ
panel/template/base.py 76.83% <56.52%> (-1.61%) ⬇️
panel/io/server.py 78.41% <64.70%> (-1.79%) ⬇️
panel/io/resources.py 87.17% <85.71%> (+4.06%) ⬆️
panel/command/serve.py 37.89% <100.00%> (+0.62%) ⬆️
panel/tests/test_server.py 100.00% <100.00%> (ø)
panel/util.py 85.09% <100.00%> (ø)
panel/widgets/slider.py 84.16% <0.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c4408b...b80f01f. Read the comment docs.

Copy link
Member

@maximlt maximlt left a comment

Choose a reason for hiding this comment

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

Would it make sense to show in the console logs what files are served?

panel/io/server.py Outdated Show resolved Hide resolved
panel/io/server.py Outdated Show resolved Hide resolved
panel/io/server.py Outdated Show resolved Hide resolved
@philippjfr
Copy link
Member Author

Would it make sense to show in the console logs what files are served?

Don't think so, the StaticFileHandler doesn't do so and failed requests are logged.

panel/io/resources.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants