Skip to content

Commit 021f7cf

Browse files
committed
Json handler
1 parent 8cb53fb commit 021f7cf

File tree

7 files changed

+359
-17
lines changed

7 files changed

+359
-17
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tokio = { version = "0.2.21", features = [
2929
"rt-threaded",
3030
"macros",
3131
"tcp",
32+
"sync",
3233
"signal"
3334
] }
3435
tokio-rustls = "0.13.1"
@@ -44,6 +45,10 @@ mime_guess = "2.0.3"
4445
urlencoding = "1.1.1"
4546
hyper-rustls = "0.20.0"
4647
http-serde = "1.0.1"
48+
serde_json = "1.0.55"
49+
json-patch = "0.2.6"
50+
bytes = "0.5.5"
51+
mime = "0.3.16"
4752

4853
[build-dependencies]
4954
vergen = "3.1.0"

src/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub enum RouteKind {
4949
Dir(DirRoute),
5050
File(FileRoute),
5151
Proxy(ProxyRoute),
52+
Json(JsonRoute),
5253
}
5354

5455
#[derive(Debug, Deserialize)]
@@ -61,6 +62,13 @@ pub struct FileRoute {
6162
pub path: PathBuf,
6263
}
6364

65+
#[derive(Debug, Deserialize)]
66+
pub struct JsonRoute {
67+
pub path: PathBuf,
68+
#[serde(default)]
69+
pub pretty: bool,
70+
}
71+
6472
#[derive(Debug, Deserialize)]
6573
#[serde(rename_all = "kebab-case")]
6674
pub struct ProxyRoute {
@@ -86,6 +94,7 @@ impl Route {
8694
RouteKind::Dir(dir) => dir.validate(),
8795
RouteKind::File(file) => file.validate(),
8896
RouteKind::Proxy(proxy) => proxy.validate(),
97+
RouteKind::Json(json) => json.validate(),
8998
}
9099
}
91100
}
@@ -119,3 +128,12 @@ impl ProxyRoute {
119128
Ok(())
120129
}
121130
}
131+
132+
impl JsonRoute {
133+
fn validate(&self) -> Result<()> {
134+
if !self.path.is_file() {
135+
bail!("`{}` is not a file", self.path.display());
136+
}
137+
Ok(())
138+
}
139+
}

0 commit comments

Comments
 (0)