Static folder example at https://docs.shuttle.rs/e...
# help
c
Copy code
rust
use std::path::PathBuf;

use axum::{routing::get, Router};
use axum_extra::routing::SpaRouter;

async fn hello_world() -> &'static str {
    "Hello, world!"
}

#[shuttle_runtime::main]
async fn axum(
    // Name your static assets folder by passing `folder = <name>` to `StaticFolder`
    // If you don't pass a name, it will default to `static`.
    #[shuttle_static_folder::StaticFolder(folder = "assets")] static_folder: PathBuf,
) -> shuttle_axum::ShuttleAxum {
    let router = Router::new()
        .route("/hello", get(hello_world))
        .merge(SpaRouter::new("/assets", static_folder).index_file("index.html"));

    Ok(router.into())
}
Error:
Copy code
2023-05-13T08:39:12.639700265Z DEBUG error[E0432]: unresolved import `axum_extra::routing::SpaRouter`
 --> src/main.rs:4:5
  |
4 | use axum_extra::routing::SpaRouter;
  |     ^^^^^^^^^^^^^^^^^^^^^---------
  |     |                    |
  |     |                    help: a similar name exists in the module: `Router`
  |     no `SpaRouter` in `routing`


2023-05-13T08:39:12.671257094Z DEBUG error[E0599]: no function or associated item named `new` found for struct `StaticFolder` in the current scope
  --> src/main.rs:10:1
   |
10 | #[shuttle_runtime::main]
   | ^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `StaticFolder<'_>`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: this error originates in the attribute macro `shuttle_runtime::main` (in Nightly builds, run with -Z macro-backtrace for more info)
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
1  | use shuttle_service::ResourceBuilder;
   |
Dependencies:
Copy code
toml
[dependencies]
shuttle-runtime = "0.14.0"
axum = "0.6.17"
shuttle-axum = "0.14.0"
tokio = "1.28.0"
shuttle-static-folder = "0.16.0"
axum-extra = "0.7.4"
Rust version: rust 1.71.0-nightly What is causing this?
g
Hey there! Sorry about this; our example seems to be outdated. Axum has ditches the SpaRouter in favor of ServeDir. Docs: https://docs.rs/tower-http/latest/tower_http/services/struct.ServeDir.html Iirc, @agreeable-painting-48846 has an up to date example he used recently.
c
And the second error?
Copy code
no function or associated item named `new` found for struct `StaticFolder` in the current scope
  --> src/main.rs:10:1
   |
10 | #[shuttle_runtime::main]
   | ^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `StaticFolder<'_>`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: this error originates in the attribute macro `shuttle_runtime::main` (in Nightly builds, run with -Z macro-backtrace for more info)
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
1  | use shuttle_service::ResourceBuilder;
   |
Looks like a different problem, or is it the same?
a
Hey there, what version of shuttle deps/cargo-shuttle are you running?
c
cargo-shuttle 0.16.0
(
cargo shuttle --version
)
Is that what you mean?
a
Yeah 🙂 also what version of shuttle dependencies are you using on the project?
c
Copy code
toml
[dependencies]
shuttle-runtime = "0.14.0"
axum = "0.6.17"
shuttle-axum = "0.14.0"
tokio = "1.28.0"
shuttle-static-folder = "0.16.0"
axum-extra = "0.7.4"
Or do you mean something else?
a
That exactly actually
c
That was in my original message already
a
Ah sorry I'm on my phone and away from a computer at the moment 😅 Could you try updating shuttle-runtime and shuttle-axum to 0.16.0?
c
The error is gone, thanks!
Why does it not use that version by default though?
a
Not sure, I'll query this with engi. Thanks for reporting the issue
c
No problem!
I just initialized the crate with
cargo shuttle init
Also, updating the example is probably a good idea, since that's what people get a first impression of.
How would I use the
ServeDir
here? Would I just remove the
static_folder
macro and argument?
And
Router.merge
doesn't work with it
a
The static folder macro just returns a pathbuf that allows static files to be ran on shuttle - wrt servedir, that didn't actually end up working for me so I ended up using a workaround with Tower/tower_http