Skip to content

Commit bd82a20

Browse files
committed
feat(route): fallback
1 parent 79ba7ee commit bd82a20

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use async_graphql::{EmptyMutation, EmptySubscription, Schema};
55
use async_graphql_warp::Response;
66
use dotenv::dotenv;
77
use log::debug;
8-
use std::convert::Infallible;
8+
use std::{convert::Infallible, path::Path};
99
use structopt::StructOpt;
1010
use warp::{http::Response as HttpResponse, Filter};
1111

@@ -57,9 +57,11 @@ async fn main() {
5757
.body(playground_source(GraphQLPlaygroundConfig::new("/query")))
5858
});
5959

60-
let static_files = warp::get().and(warp::fs::dir(opt.static_file_path));
60+
let static_files = warp::get().and(warp::fs::dir(opt.static_file_path.clone()));
61+
let path = Path::new(&opt.static_file_path).join("index.html");
62+
let fallback = warp::fs::file(path);
6163

62-
let routes = graphql_playground.or(graphql_post).or(static_files);
64+
let routes = graphql_playground.or(graphql_post).or(static_files).or(fallback);
6365

6466
warp::serve(routes).run(([0, 0, 0, 0], 8000)).await;
6567
}

0 commit comments

Comments
 (0)