axum-impl-static-files

Configure tower-http static file serving in Axum with correct service mounting.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-static-files
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-impl-static-files
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-static-files
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-static-files

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents common, hard-to-debug Axum static-file routing mistakes by giving deterministic, version-stable guidance for serving files and SPAs with the correct tower-http service mounting patterns and HTTP status semantics.

Core Features & Use Cases

  • Correct Service vs Layer usage: Ensures ServeDir, ServeFile, and SetStatus are mounted as route services (.nest_service, .fallback_service, .route_service), never passed to .layer().
  • Accurate prefix handling: Avoids the “double prefix” bug by explaining how .nest_service() strips the URL prefix before the filesystem service sees the path.
  • Honest SPA fallback behavior: Implements the canonical SPA pattern that returns index.html with 404 status for unknown URLs, using SetStatus and not_found_service.

Quick Start

Use the axum-impl-static-files skill when your Axum app must serve a CSS/JS/image directory under a URL prefix and you want an SPA fallback that loads index.html for unknown routes while returning HTTP 404.

Frequently Asked Questions about axum-impl-static-files

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I serve a static directory in Axum without a double prefix bug?

To serve a static directory in Axum without a double prefix bug, mount the tower-http ServeDir service using .nest_service(), which automatically strips the URL prefix before the filesystem service evaluates the path.

How do I configure SPA fallback in Axum to return index.html with a 404 status?

Configure SPA fallback in Axum by combining ServeDir with not_found_service pointing to index.html and wrapping it with SetStatus to enforce a 404 response, requiring the tower-http fs and set-status feature flags.

Why does ServeDir not work when passed to .layer() in Axum?

ServeDir does not work with .layer() because it is a Service rather than a Layer. You must mount ServeDir, ServeFile, and SetStatus as route services using .nest_service(), .fallback_service(), or .route_service().

Does Axum 0.8 static file serving require different tower-http mounting methods than 0.7?

Axum 0.8 static file serving uses the same deterministic tower-http service mounting patterns as 0.7. Both versions require mounting ServeDir and ServeFile via .nest_service() or .fallback_service() rather than using layers.

What is the correct way to serve a single static file in Axum?

The correct way to serve a single static file in Axum is to use the tower-http ServeFile service mounted directly via .route_service() at the specific URL path, ensuring proper Service-not-Layer semantics.