Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces static file serving to the
IOServerframework, enabling seamless support for single-page applications (SPAs) and static assets. The new functionality allows serving a directory of static files (such as a built frontend) and provides an optional SPA fallback mode, ensuring client-side routing works as expected. Comprehensive tests have been added to verify all static serving scenarios.Key changes:
Static file serving and SPA fallback support
rootDiroption toIOServerOptionsand constructor, enabling serving of static files from a specified directory using@fastify/static. If the directory does not exist, static serving is safely disabled with a warning. (src/IOServer.ts,package.json) [1] [2] [3]spaFallbackoption (default:true) that, when enabled withrootDir, servesindex.htmlfor any unmatched route—allowing SPA client-side routers to function correctly. If disabled, unmatched routes return the standard 404 JSON response. (src/IOServer.ts) [1] [2] [3]Core implementation and API changes
@fastify/staticplugin conditionally in thesetupPluginsmethod and updated the not-found handler to support SPA fallback or default 404s as appropriate. (src/IOServer.ts) [1] [2]2.1.0to reflect the new feature. (package.json,src/IOServer.ts) [1] [2]Testing
IOServer.static.test.ts) covering all static file serving behaviors: constructor handling, static file and asset serving, SPA fallback logic, API route priority, and default 404 handling when static serving is disabled. (tests/unit/IOServer.static.test.ts)These changes provide robust, production-ready static file serving for SPAs and static assets, with full test coverage and backward compatibility for existing API-only usage.