Skip to content

Conversation

@imdhemy
Copy link
Member

@imdhemy imdhemy commented Nov 19, 2025

This PR adds a small built-in middleware to serve static files. The files are served by default from the public directory, and the default index file is index.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 to public
    • index: Configures the index file name. Defaults to index.html

Closes #74

Copy link
Contributor

Copilot AI left a 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 serveStaticFiles middleware with 404 error handling that falls through to the next middleware
  • Configuration interface StaticFilesOptions added to KoalaConfig for customizing static file serving behavior
  • Added @koa/send dependency 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.

@imdhemy imdhemy merged commit fe0369f into 2.x Nov 19, 2025
1 check passed
@imdhemy imdhemy deleted the support-serving-static-files branch November 19, 2025 22:19
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 serving static files

2 participants