spin-kitchensink icon indicating copy to clipboard operation
spin-kitchensink copied to clipboard

Static server should try to read `index.html` if asset is a directory

Open ecumene opened this issue 2 years ago • 0 comments

https://github.com/fermyon/spin-kitchensink/blob/b25fe9315617b58363aff069264b58b1e947b566/rust-static-assets/src/lib.rs#L25

I got this working by

fn read(path: &str) -> Result<Bytes> {
    let path_obj = Path::new(path);
    let mut file = if path_obj.is_dir() {
        File::open(path_obj.join("index.html"))
            .with_context(|| anyhow!("tried directory index {}", path))?
    } else {
        File::open(path).with_context(|| anyhow!("cannot open {}", path))?
    };

    ...

}

ecumene avatar May 07 '22 03:05 ecumene