aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config.rs6
-rw-r--r--src/main.rs7
-rw-r--r--src/renderer.rs4
-rw-r--r--tests/bind.rs1
-rw-r--r--tests/serve_request.rs8
5 files changed, 12 insertions, 14 deletions
diff --git a/src/config.rs b/src/config.rs
index ae260af..73fcec2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -47,7 +47,7 @@ pub struct MiniserveConfig {
/// Show hidden files
pub show_hidden: bool,
- /// Route prefix
+ /// Route prefix; Either empty or prefixed with slash
pub route_prefix: String,
/// Randomly generated favicon route
@@ -139,8 +139,8 @@ impl MiniserveConfig {
// Generate some random routes for the favicon and css so that they are very unlikely to conflict with
// real files.
- let favicon_route = nanoid::nanoid!(10, &ROUTE_ALPHABET);
- let css_route = nanoid::nanoid!(10, &ROUTE_ALPHABET);
+ let favicon_route = format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET));
+ let css_route = format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET));
let default_color_scheme = args.color_scheme;
let default_color_scheme_dark = args.color_scheme_dark;
diff --git a/src/main.rs b/src/main.rs
index 732abac..16feaf0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -186,11 +186,8 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.app_data(inside_config.clone())
.wrap_fn(errors::error_page_middleware)
.wrap(middleware::Logger::default())
- .route(
- &format!("/{}", inside_config.favicon_route),
- web::get().to(favicon),
- )
- .route(&format!("/{}", inside_config.css_route), web::get().to(css))
+ .route(&inside_config.favicon_route, web::get().to(favicon))
+ .route(&inside_config.css_route, web::get().to(css))
.service(
web::scope(&inside_config.route_prefix)
.wrap(middleware::Condition::new(
diff --git a/src/renderer.rs b/src/renderer.rs
index 0ac5077..544be42 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -478,8 +478,8 @@ fn page_header(title: &str, file_upload: bool, favicon_route: &str, css_route: &
meta http-equiv="X-UA-Compatible" content="IE=edge";
meta name="viewport" content="width=device-width, initial-scale=1";
- link rel="icon" type="image/svg+xml" href={ "/" (favicon_route) };
- link rel="stylesheet" href={ "/" (css_route) };
+ link rel="icon" type="image/svg+xml" href={ (favicon_route) };
+ link rel="stylesheet" href={ (css_route) };
title { (title) }
diff --git a/tests/bind.rs b/tests/bind.rs
index 1c816f0..0fa914e 100644
--- a/tests/bind.rs
+++ b/tests/bind.rs
@@ -53,6 +53,7 @@ fn bind_ipv4_ipv6(
#[case(&["-i", "0.0.0.0"])]
#[case(&["-i", "::", "-i", "0.0.0.0"])]
#[case(&["--random-route"])]
+#[case(&["--route-prefix", "/prefix"])]
fn validate_printed_urls(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
let mut child = Command::cargo_bin("miniserve")?
.arg(tmpdir.path())
diff --git a/tests/serve_request.rs b/tests/serve_request.rs
index 1491be9..d66ffd4 100644
--- a/tests/serve_request.rs
+++ b/tests/serve_request.rs
@@ -262,14 +262,14 @@ fn serve_index_instead_of_404_in_spa_mode(
}
#[rstest]
-fn serves_requests_with_path_prefix(
- #[with(["--route-prefix", "foobar"])] server: TestServer,
-) -> Result<(), Error> {
+#[case(server(&["--route-prefix", "foobar"]))]
+#[case(server(&["--route-prefix", "/foobar/"]))]
+fn serves_requests_with_route_prefix(#[case] server: TestServer) -> Result<(), Error> {
let url_without_route = server.url();
let status = reqwest::blocking::get(url_without_route)?.status();
assert_eq!(status, StatusCode::NOT_FOUND);
- let url_with_route = format!("{}{}", server.url(), "foobar");
+ let url_with_route = server.url().join("foobar")?;
let status = reqwest::blocking::get(url_with_route)?.status();
assert_eq!(status, StatusCode::OK);