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

feat: platform agnostic serveStatic utility #480

Merged
merged 2 commits into from
Aug 1, 2023
Merged

feat: platform agnostic serveStatic utility #480

merged 2 commits into from
Aug 1, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 1, 2023

πŸ”— Linked issue

Resolves #31

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR implements a platform-agnostic serveStatic utility. In order to integrate with each platform, getMeta and getContents method have to be implemented according to the platform requirements.

Two additional/optional encodings and indexNames allow to optionally support serving compressed assets and with custom index.html check.

A fallthrough flag can also be provided and when enabled, the middleware avoids to throw an error or return 404 in case of asset is not matching and instead returns Promise<false> for custom logic handling and overlapping routes.

This implementation is based on nitro static.ts which @danielroe helped a lot on it's implementation and will be used in downstream after landing.

In future steps, we might also support unstorage and node fs adapters for serve static.

Co-Authored-By: Daniel Roe <daniel@roe.dev>

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #480 (9d98d88) into main (5ec4b30) will increase coverage by 2.80%.
The diff coverage is 98.98%.

@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
+ Coverage   78.62%   81.42%   +2.80%     
==========================================
  Files          27       28       +1     
  Lines        3036     3231     +195     
  Branches      450      489      +39     
==========================================
+ Hits         2387     2631     +244     
+ Misses        649      600      -49     
Files Changed Coverage Ξ”
src/utils/static.ts 98.96% <98.96%> (ΓΈ)
src/utils/index.ts 100.00% <100.00%> (ΓΈ)

... and 4 files with indirect coverage changes

@pi0 pi0 merged commit d97e921 into main Aug 1, 2023
6 checks passed
@pi0 pi0 deleted the feat/serve-static branch August 1, 2023 18:53
This was referenced Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support for serving static files
1 participant