Skip to content

Commit 288645f

Browse files
authored
Axum 0.8 for axum, axum static files examples (#350)
1 parent 889bec3 commit 288645f

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

examples/axum-static-files.mdx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Static Files"
3-
'og:title': "Static Files with Axum - Shuttle Docs"
3+
"og:title": "Static Files with Axum - Shuttle Docs"
44
description: "This article walks you through setting up static files with Axum, a powerful Rust framework maintained by the Tokio-rs team."
55
---
66

@@ -19,19 +19,15 @@ shuttle init --from shuttle-hq/shuttle-examples --subfolder axum/static-files
1919
## Code
2020

2121
<CodeGroup>
22+
2223
```rust src/main.rs
23-
use axum::{routing::get, Router};
24+
use axum::Router;
2425
use tower_http::services::ServeDir;
2526

26-
async fn hello_world() -> &'static str {
27-
"Hello, world!"
28-
}
29-
3027
#[shuttle_runtime::main]
3128
async fn main() -> shuttle_axum::ShuttleAxum {
32-
let router = Router::new()
33-
.route("/", get(hello_world))
34-
.nest_service("/assets", ServeDir::new("assets"));
29+
// ServeDir falls back to serve index.html when requesting a directory
30+
let router = Router::new().fallback_service(ServeDir::new("assets"));
3531

3632
Ok(router.into())
3733
}
@@ -40,12 +36,12 @@ async fn main() -> shuttle_axum::ShuttleAxum {
4036
```html assets/index.html
4137
<!DOCTYPE html>
4238
<html>
43-
<head>
44-
<title>Static Files</title>
45-
</head>
46-
<body>
47-
<p>This is an example of serving static files with Axum and Shuttle.</p>
48-
</body>
39+
<head>
40+
<title>Static Files</title>
41+
</head>
42+
<body>
43+
<p>This is an example of serving static files with Axum and Shuttle.</p>
44+
</body>
4945
</html>
5046
```
5147

@@ -57,11 +53,11 @@ edition = "2021"
5753
publish = false
5854

5955
[dependencies]
60-
axum = "0.7.3"
56+
axum = "0.8"
6157
shuttle-axum = "0.56.0"
6258
shuttle-runtime = "0.56.0"
6359
tokio = "1.28.2"
64-
tower-http = { version = "0.5.0", features = ["fs"] }
60+
tower-http = { version = "0.6", features = ["fs"] }
6561
```
6662

6763
```toml Shuttle.toml
@@ -70,6 +66,7 @@ assets = [
7066
"assets",
7167
]
7268
```
69+
7370
</CodeGroup>
7471

7572
## Usage
@@ -83,3 +80,4 @@ You can extend this example by adding more routes that serve other files.
8380
<Snippet file="other-frameworks.mdx" />
8481

8582
<Snippet file="check-examples.mdx" />
83+
```

examples/axum.mdx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
---
22
title: "Hello World"
3-
'og:title': "Hello World with Axum - Shuttle Docs"
4-
description:
5-
"Axum is a web application framework that focuses on ergonomics and
3+
"og:title": "Hello World with Axum - Shuttle Docs"
4+
description: "Axum is a web application framework that focuses on ergonomics and
65
modularity."
76
---
87

98
This section revolves around simple Axum examples you can get quickly started with by following these 3 steps:
9+
1010
1. Initialize a new Axum project by running the `shuttle init --template axum` command
1111
2. Copy pasting the contents of the example you want to deploy -- make sure to check the tabs of the snippet(s) to ensure you are copying the right code/file
1212
3. Running the `shuttle deploy` command
1313

14-
<Tip>If you are looking for step-by-step guides, check out our [Tutorials](/templates/tutorials) section.</Tip>
14+
<Tip>
15+
If you are looking for step-by-step guides, check out our
16+
[Tutorials](/templates/tutorials) section.
17+
</Tip>
1518

1619
You can clone the example below by running the following (you'll need `shuttle` CLI installed):
1720

@@ -20,6 +23,7 @@ shuttle init --template axum
2023
```
2124

2225
<CodeGroup>
26+
2327
```rust src/main.rs
2428
use axum::{routing::get, Router};
2529

@@ -28,8 +32,7 @@ async fn hello_world() -> &'static str {
2832
}
2933

3034
#[shuttle_runtime::main]
31-
async fn axum() -> shuttle_axum::ShuttleAxum {
32-
35+
async fn main() -> shuttle_axum::ShuttleAxum {
3336
let router = Router::new().route("/", get(hello_world));
3437

3538
Ok(router.into())
@@ -43,11 +46,12 @@ version = "0.1.0"
4346
edition = "2021"
4447

4548
[dependencies]
46-
axum = "0.7.4"
49+
axum = "0.8"
4750
shuttle-axum = "0.56.0"
4851
shuttle-runtime = "0.56.0"
4952
tokio = "1.28.2"
5053
```
54+
5155
</CodeGroup>
5256

5357
---

0 commit comments

Comments
 (0)