~repos /rust-embed
git clone https://pyrossh.dev/repos/rust-embed.git
rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
f5dd61b4
—
Peter John 2 years ago
Merge pull request #201 from DusterTheFirst/axum-fix
- examples/axum-spa/main.rs +3 -4
- examples/axum.rs +1 -2
examples/axum-spa/main.rs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
use axum::{
|
|
2
2
|
body::{boxed, Full},
|
|
3
|
-
handler::Handler,
|
|
4
3
|
http::{header, StatusCode, Uri},
|
|
5
|
-
response::Response,
|
|
4
|
+
response::{IntoResponse, Response},
|
|
6
5
|
routing::Router,
|
|
7
6
|
};
|
|
8
7
|
use rust_embed::RustEmbed;
|
|
@@ -16,14 +15,14 @@ struct Assets;
|
|
|
16
15
|
|
|
17
16
|
#[tokio::main]
|
|
18
17
|
async fn main() {
|
|
19
|
-
let app = Router::new().fallback(static_handler
|
|
18
|
+
let app = Router::new().fallback(static_handler);
|
|
20
19
|
|
|
21
20
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
22
21
|
println!("listening on {}", addr);
|
|
23
22
|
axum::Server::bind(&addr).serve(app.into_make_service()).await.unwrap();
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
async fn static_handler(uri: Uri) ->
|
|
25
|
+
async fn static_handler(uri: Uri) -> impl IntoResponse {
|
|
27
26
|
let path = uri.path().trim_start_matches('/');
|
|
28
27
|
|
|
29
28
|
if path.is_empty() || path == INDEX_HTML {
|
examples/axum.rs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
use axum::{
|
|
2
2
|
body::{boxed, Full},
|
|
3
|
-
handler::HandlerWithoutStateExt,
|
|
4
3
|
http::{header, StatusCode, Uri},
|
|
5
4
|
response::{Html, IntoResponse, Response},
|
|
6
5
|
routing::{get, Router},
|
|
@@ -14,7 +13,7 @@ async fn main() {
|
|
|
14
13
|
let app = Router::new()
|
|
15
14
|
.route("/", get(index_handler))
|
|
16
15
|
.route("/index.html", get(index_handler))
|
|
17
|
-
.
|
|
16
|
+
.route("/dist/*file", get(static_handler))
|
|
18
17
|
.fallback_service(get(not_found));
|
|
19
18
|
|
|
20
19
|
// Start listening on the given address.
|