Skip to content

Commit fc6ff38

Browse files
daxpeddajakobhellermann
authored andcommitted
Custom serve directory
1 parent 9760eaa commit fc6ff38

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ fn main() -> Result<(), anyhow::Error> {
1919
let title = std::env::var("CARGO_PKG_NAME").unwrap_or_else(|_| "".to_string());
2020
let address =
2121
std::env::var("WASM_SERVER_RUNNER_ADDRESS").unwrap_or_else(|_| "127.0.0.1".to_string());
22+
let directory =
23+
std::env::var("WASM_SERVER_RUNNER_DIRECTORY").unwrap_or_else(|_| String::from("."));
2224
let https =
2325
std::env::var("WASM_SERVER_RUNNER_HTTPS").unwrap_or_else(|_| String::from("0")) == "1";
2426
let no_module =
2527
std::env::var("WASM_SERVER_RUNNER_NO_MODULE").unwrap_or_else(|_| String::from("0")) == "1";
2628

27-
let options = Options { title, address, https, no_module };
29+
let options = Options { title, address, directory, https, no_module };
2830

2931
let wasm_file = std::env::args()
3032
.nth(1)

src/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn generate_version() -> String {
2323
pub struct Options {
2424
pub title: String,
2525
pub address: String,
26+
pub directory: String,
2627
pub https: bool,
2728
pub no_module: bool,
2829
}
@@ -51,7 +52,8 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
5152
};
5253
let html = html.replace("{{ TITLE }}", &options.title);
5354

54-
let serve_dir = get_service(ServeDir::new(".")).handle_error(internal_server_error);
55+
let serve_dir =
56+
get_service(ServeDir::new(options.directory)).handle_error(internal_server_error);
5557

5658
let serve_wasm = || async move {
5759
([("content-encoding", "br")], WithContentType("application/wasm", compressed_wasm))

0 commit comments

Comments
 (0)