-
Notifications
You must be signed in to change notification settings - Fork 1
feat(handler) Support serving static files #75
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
Conversation
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.
Pull Request Overview
This PR introduces built-in middleware for serving static files from a configurable directory. The implementation delegates to @koa/send and allows customization of the root directory (defaults to public) and index file (defaults to index.html).
Key changes:
- New
serveStaticFilesmiddleware with 404 error handling that falls through to the next middleware - Configuration interface
StaticFilesOptionsadded toKoalaConfigfor customizing static file serving behavior - Added
@koa/senddependency for file serving functionality
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Http/Files/StaticFilesMiddleware.ts | Core middleware implementation that wraps @koa/send with error handling |
| src/Http/Files/types.ts | TypeScript interface defining static files configuration options |
| src/Http/Files/index.ts | Barrel export for the Files module |
| src/Http/Error/types.ts | HttpError class extending Koa's HttpError for type safety |
| src/Http/Error/index.ts | Barrel export for the Error module |
| src/Config/types.ts | Updated KoalaConfig interface to include optional staticFiles configuration |
| src/Application/ApplicationFactory.ts | Integrated static files middleware into the application factory |
| src/Application/ApplicationFactory.test.ts | Integration test verifying static file serving from custom directory |
| src/Http/Files/StaticFilesMiddleware.test.ts | Unit tests for middleware functionality including 404 handling |
| tests/fixtures/sample.txt | Test fixture file for integration testing |
| package.json | Added @koa/send dependency |
| package-lock.json | Dependency updates including @koa/send and various package version bumps |
| eslint.config.js | Removed @typescript-eslint/consistent-type-exports rule |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR adds a small built-in middleware to serve static files. The files are served by default from the
publicdirectory, and the default index file isindex.html, but these options are still configurable.Available options:
staticFiles: The parent key of the configuration:root: Configures the root directory of the static files. Defaults topublicindex: Configures the index file name. Defaults toindex.htmlCloses #74