Skip to content

Add multi-directory static file serving#3920

Open
ban-xiu wants to merge 8 commits intoactix:mainfrom
ban-xiu:feat-files-array-support
Open

Add multi-directory static file serving#3920
ban-xiu wants to merge 8 commits intoactix:mainfrom
ban-xiu:feat-files-array-support

Conversation

@ban-xiu
Copy link

@ban-xiu ban-xiu commented Feb 12, 2026

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

Add Files::new_from_array() and Files::new_multiple() methods to support multiple directories from array and iterator, and implement multi-directory static file serving with priority order.
Close #3402

@github-actions github-actions bot added the A-files project: actix-files label Feb 12, 2026
@ban-xiu ban-xiu closed this Feb 14, 2026
@ban-xiu ban-xiu reopened this Feb 14, 2026
Comment on lines +153 to +154
log::error!("Specified path is not a directory: {:?}", orig_dir);
orig_dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the comment?


// full file path
let path = this.directory.join(&path_on_disk);
// Try to find file in multiple directories
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks our current behavior, in particular for try_compressed.

Comment on lines -117 to +120
let dir = Directory::new(self.directory.clone(), path);
let dir = Directory::new(path.clone(), path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes semantics, why do you need change base?

let mut found_path = None;
let mut last_err = None;

for directory in &this.directories {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if Files::new_from_array("/", &["./dist", "./public"]).index_file("index.html") is passed and you want to look up ./public/index.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-files project: actix-files B-semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multiple folders as static directories

2 participants