Skip to content

Commit 33c114c

Browse files
authored
feat: support for old browsers with legacy-ui (#490)
- Provides support for rendering a File Explorer on non-WASM browsers, enabled by using: ```bash # modern (wasm powered) ui (default) http-server start --service file-explorer # legacy ui http-server start --service file-server ``` - Introduces the `Handler` trait for allowing further handlers in the future by just introducing a trait implementation. Both `FileExplorer` and `FileServer` are `Handler` compliant.
1 parent 9f6c3d4 commit 33c114c

File tree

23 files changed

+1518
-96
lines changed

23 files changed

+1518
-96
lines changed

Cargo.lock

Lines changed: 170 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ members = [
77
default-members = ["src/http-server"]
88
resolver = "1"
99

10+
[workspace.package]
11+
authors = ["Leo Borai <[email protected]>"]
12+
categories = ["web-programming", "web-programming::http-server"]
13+
description = "Simple and configurable command-line HTTP server"
14+
documentation = ""
15+
edition = "2024"
16+
include = ["/ui", "/src/"]
17+
keywords = ["configurable", "http", "server", "serve", "static"]
18+
license = "MIT OR Apache-2.0"
19+
repository = "https://github.com/http-server-rs/http-server"
20+
readme = "./README.md"
21+
version = "1.0.0-pre.6fa7635"
22+
1023
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1124

1225
[workspace.dependencies]
@@ -19,6 +32,7 @@ dirs = "5.0.1"
1932
futures = "0.3.31"
2033
gloo = "0.11.0"
2134
gloo-file = "0.3.0"
35+
handlebars = "6.3.2"
2236
humansize = "2.1.3"
2337
http = "1.1.0"
2438
http-body-util = "0.1"

src/http-server/Cargo.toml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
22
name = "http-server"
3-
version = "1.0.0-pre.6fa7635"
4-
authors = ["Leo Borai <[email protected]>"]
5-
edition = "2021"
6-
description = "Simple and configurable command-line HTTP server"
7-
repository = "https://github.com/http-server-rs/http-server"
8-
categories = ["web-programming", "web-programming::http-server"]
9-
keywords = ["configurable", "http", "server", "serve", "static"]
10-
license = "MIT OR Apache-2.0"
11-
readme = "../../README.md"
12-
include = ["/ui", "/src/"]
3+
authors.workspace = true
4+
categories.workspace = true
5+
description.workspace = true
6+
documentation.workspace = true
7+
edition.workspace = true
8+
keywords.workspace = true
9+
include.workspace = true
10+
license.workspace = true
11+
repository.workspace = true
12+
version.workspace = true
1313

1414
[[bin]]
1515
name = "http-server"
@@ -22,8 +22,11 @@ bytes = { workspace = true }
2222
chrono = { workspace = true, features = ["serde"] }
2323
clap = { workspace = true, features = ["env", "derive", "std"] }
2424
dirs = { workspace = true }
25+
futures = { workspace = true }
26+
handlebars = { workspace = true }
2527
http = { workspace = true }
2628
http-body-util = { workspace = true }
29+
humansize = { workspace = true }
2730
hyper = { workspace = true }
2831
hyper-util = { workspace = true, features = ["full"] }
2932
libloading = { workspace = true }

src/http-server/src/cli/command/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod start;
1+
pub mod start;
22

33
use clap::Parser;
44

src/http-server/src/cli/command/start.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::net::IpAddr;
22
use std::process::exit;
3+
use std::str::FromStr;
34
use std::sync::Arc;
45

56
use anyhow::Result;
@@ -12,6 +13,24 @@ use crate::server::Server;
1213

1314
const THREAD_NAME: &str = "http-server";
1415

16+
#[derive(Clone, Debug, Parser)]
17+
pub enum Service {
18+
FileServer,
19+
FileExplorer,
20+
}
21+
22+
impl FromStr for Service {
23+
type Err = String;
24+
25+
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
26+
match s {
27+
"file-server" => Ok(Service::FileServer),
28+
"file-explorer" => Ok(Service::FileExplorer),
29+
_ => Err(format!("Invalid service: {}", s)),
30+
}
31+
}
32+
}
33+
1534
#[derive(Debug, Parser)]
1635
pub struct StartOpt {
1736
/// Host (IP) to bind the server
@@ -23,6 +42,9 @@ pub struct StartOpt {
2342
/// Enable CORS with a permissive policy
2443
#[clap(long, default_value = "false")]
2544
pub cors: bool,
45+
/// Service to run
46+
#[clap(long, default_value = "file-explorer")]
47+
pub service: Service,
2648
}
2749

2850
impl From<&StartOpt> for Config {
@@ -31,6 +53,7 @@ impl From<&StartOpt> for Config {
3153
host: val.host,
3254
port: val.port,
3355
cors: val.cors,
56+
service: val.service.clone().into(),
3457
}
3558
}
3659
}

0 commit comments

Comments
 (0)