Warp not finding File [SOLVED]

I am trying to use the new Warp crate to serve some files for a toy project. The file structure is this:

src -|
     |- main.rs
     |- file1.txt
     |- dir2 -|
              |- file2.txt

The code in main.rs is this:

fn main() -> {
    let file1 = warp::path("file1").and(warp::fs::file("./file1.txt"));
    let file2 = warp::path("file2").and(warp::fs::file("./dir2/file2.txt"));
    let routes = file1.or(file2);
    warp::serve(routes).run(([127, 0, 0, 1], 3030));

Navigating to 127.0.0.1:3030/file1 or 127.0.0.1:3030/file2 returns No such file or directory (os error 2). What am I doing wrong?

Unless Warp is doing something out of the ordinary, I'd imagine it'd resolve file paths relative to the current working directory (most likely where you ran cargo run), not src. Try either amending the paths in your filters to ./src/... or moving the files to the root of your project.

1 Like

Knew it was something like that. Thanks.

1 Like