mirror of
https://github.com/Tim-Paik/srv.git
synced 2024-10-13 00:29:43 +00:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
46b7c6379f
|
|||
39bcd56608
|
139
Cargo.lock
generated
139
Cargo.lock
generated
@ -44,9 +44,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "actix-http"
|
||||
version = "3.1.0"
|
||||
version = "3.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd2e9f6794b5826aff6df65e3a0d0127b271d1c03629c774238f3582e903d4e4"
|
||||
checksum = "6f9ffb6db08c1c3a1f4aef540f1a63193adc73c4fbd40b75a95fc8c5258f6e51"
|
||||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-rt",
|
||||
@ -208,7 +208,7 @@ dependencies = [
|
||||
"serde_urlencoded",
|
||||
"smallvec",
|
||||
"socket2",
|
||||
"time 0.3.9",
|
||||
"time",
|
||||
"url",
|
||||
]
|
||||
|
||||
@ -432,7 +432,6 @@ dependencies = [
|
||||
"libc",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time 0.1.44",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
@ -460,9 +459,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.2.5"
|
||||
version = "3.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d53da17d37dba964b9b3ecb5c5a1f193a2762c700e6829201e645b9381c99dc7"
|
||||
checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
@ -477,9 +476,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5538cd660450ebeb4234cfecf8f2284b844ffc4c50531e66d584ad5b91293613"
|
||||
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
@ -497,7 +496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
"time 0.3.9",
|
||||
"time",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
@ -521,9 +520,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.9"
|
||||
version = "0.8.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ff1f980957787286a554052d03c7aee98d99cc32e09f6d45f0a814133c87978"
|
||||
checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@ -531,9 +530,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.3"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array 0.14.5",
|
||||
"typenum",
|
||||
@ -694,7 +693,7 @@ checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -742,9 +741,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.1"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
@ -827,9 +826,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.0"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c6392766afd7964e2531940894cffe4bd8d7d17dbc3c1c4857040fd4b33bdb3"
|
||||
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
@ -959,13 +958,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.3"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799"
|
||||
checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"wasi",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
@ -1009,9 +1008,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.12.0"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
|
||||
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
@ -1021,9 +1020,9 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.1.0"
|
||||
version = "6.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
|
||||
checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
@ -1171,18 +1170,18 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.39"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
|
||||
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.18"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
|
||||
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@ -1228,9 +1227,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.6"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
|
||||
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@ -1239,9 +1238,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.26"
|
||||
version = "0.6.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
|
||||
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
@ -1321,24 +1320,24 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.10"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c"
|
||||
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.137"
|
||||
version = "1.0.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
|
||||
checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.137"
|
||||
version = "1.0.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
|
||||
checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1347,9 +1346,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.81"
|
||||
version = "1.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
|
||||
checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@ -1434,9 +1433,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.8.0"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
@ -1456,12 +1455,11 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "srv"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-web",
|
||||
"actix-web-httpauth",
|
||||
"chrono",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"lazy_static",
|
||||
@ -1472,6 +1470,7 @@ dependencies = [
|
||||
"serde",
|
||||
"sha2",
|
||||
"tera",
|
||||
"time",
|
||||
"toml",
|
||||
"urlencoding",
|
||||
]
|
||||
@ -1484,9 +1483,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.96"
|
||||
version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
|
||||
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1554,20 +1553,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi 0.10.0+wasi-snapshot-preview1",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd"
|
||||
checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"libc",
|
||||
@ -1598,10 +1586,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.19.2"
|
||||
version = "1.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439"
|
||||
checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
"libc",
|
||||
"memchr",
|
||||
@ -1662,9 +1651,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.27"
|
||||
version = "0.1.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921"
|
||||
checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
@ -1677,9 +1666,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
||||
|
||||
[[package]]
|
||||
name = "ucd-trie"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
|
||||
checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c"
|
||||
|
||||
[[package]]
|
||||
name = "uncased"
|
||||
@ -1757,15 +1746,15 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
|
||||
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.19"
|
||||
version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9"
|
||||
checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
@ -1811,12 +1800,6 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
@ -1899,9 +1882,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.22.3"
|
||||
version = "0.22.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf"
|
||||
checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
@ -3,13 +3,12 @@ authors = ["Tim_Paik <timpaikc@outlook.com>"]
|
||||
description = "simple http server written in rust"
|
||||
edition = "2018"
|
||||
name = "srv"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
|
||||
[dependencies]
|
||||
actix-files = "0.6"
|
||||
actix-web = {version = "4.1", features = ["rustls"]}
|
||||
actix-web-httpauth = "0.6"
|
||||
chrono = "0.4"
|
||||
clap = {version = "3.2", features = ["wrap_help", "color", "cargo"]}
|
||||
env_logger = "0.9"
|
||||
lazy_static = "1.4"
|
||||
@ -20,6 +19,7 @@ rustls-pemfile = "1.0"
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
sha2 = "0.10"
|
||||
tera = "1.16"
|
||||
time = { version = "0.3", features = ["formatting", "parsing"] }
|
||||
toml = "0.5"
|
||||
urlencoding = "2.1"
|
||||
|
||||
|
172
src/main.rs
172
src/main.rs
@ -252,9 +252,11 @@ fn render_index(
|
||||
}
|
||||
};
|
||||
let modified = match metadata.modified() {
|
||||
Ok(time) => chrono::DateTime::<chrono::Local>::from(time)
|
||||
.format("%Y/%m/%d %H:%M:%S")
|
||||
.to_string(),
|
||||
Ok(time) => time::OffsetDateTime::from(time)
|
||||
.format(time::macros::format_description!(
|
||||
"[year]/[month]/[day] [hour]:[minute]:[second]"
|
||||
))
|
||||
.unwrap_or_else(|_| "".to_string()),
|
||||
Err(e) => {
|
||||
error!(target: "read_dir", "[ERROR] Read modified time error: {}", e.to_string());
|
||||
continue;
|
||||
@ -479,7 +481,6 @@ async fn main() -> std::io::Result<()> {
|
||||
open_in_browser(&url);
|
||||
}
|
||||
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("doc") {
|
||||
if !matches.is_present("log") {
|
||||
set_var("RUST_LOG", "info,actix_web::middleware::logger=off");
|
||||
@ -504,11 +505,15 @@ async fn main() -> std::io::Result<()> {
|
||||
if record.target() == "actix_web::middleware::logger" {
|
||||
let data: Vec<&str> = data.splitn(5, '^').collect();
|
||||
let time = blue.value(
|
||||
data[0]
|
||||
.parse::<chrono::DateTime<chrono::Utc>>()
|
||||
.unwrap()
|
||||
.format("%Y/%m/%d %H:%M:%S")
|
||||
.to_string(),
|
||||
time::OffsetDateTime::parse(
|
||||
data[0],
|
||||
&time::format_description::well_known::Rfc3339,
|
||||
)
|
||||
.unwrap_or(time::OffsetDateTime::UNIX_EPOCH)
|
||||
.format(time::macros::format_description!(
|
||||
"[year]/[month]/[day] [hour]:[minute]:[second]"
|
||||
))
|
||||
.unwrap_or_else(|_| "".to_string()),
|
||||
);
|
||||
let ipaddr = blue.value(data[1]);
|
||||
let status_code = data[2].parse().unwrap_or(500);
|
||||
@ -550,7 +555,11 @@ async fn main() -> std::io::Result<()> {
|
||||
return writeln!(buf, "\r{}", green.value(data));
|
||||
}
|
||||
if data == "SIGINT received; starting forced shutdown" {
|
||||
return writeln!(buf, "\r{}", green.value("[INFO] SIGINT received; starting forced shutdown"));
|
||||
return writeln!(
|
||||
buf,
|
||||
"\r{}",
|
||||
green.value("[INFO] SIGINT received; starting forced shutdown")
|
||||
);
|
||||
// Add '\r' to remove the input ^C
|
||||
}
|
||||
return Ok(());
|
||||
@ -570,78 +579,78 @@ async fn main() -> std::io::Result<()> {
|
||||
})
|
||||
.init();
|
||||
|
||||
let addr = if let Some(matches) = matches.subcommand_matches("doc") {
|
||||
let mut cargo_toml = match std::fs::File::open("./Cargo.toml") {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
error!("[ERROR] {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let mut contents = String::new();
|
||||
match cargo_toml.read_to_string(&mut contents) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
error!("[ERROR] {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let contents: CargoToml = match toml::from_str(&contents) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
error!("[ERROR] {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let crate_name = contents.package.name;
|
||||
info!("[INFO] Generating document (may take a while)");
|
||||
match std::process::Command::new("cargo").arg("doc").output() {
|
||||
Ok(output) => {
|
||||
let output = std::str::from_utf8(&output.stderr).unwrap_or("");
|
||||
if output.starts_with("error: could not find `Cargo.toml` in") {
|
||||
error!("[ERROR] Cargo.toml Not Found");
|
||||
return Ok(());
|
||||
} else if output.starts_with("error: ") {
|
||||
error!(
|
||||
"[ERROR] {}",
|
||||
output.strip_prefix("error: ").unwrap_or(output)
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("[ERROR] Cargo Error: {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let path = Path::new("./target/doc/");
|
||||
let mut index_path = path.to_path_buf();
|
||||
index_path.push(crate_name.to_string() + "/index.html");
|
||||
if !index_path.exists() || !index_path.is_file() {
|
||||
error!("[ERROR] Cargo Error: doc path not found");
|
||||
let addr = if let Some(matches) = matches.subcommand_matches("doc") {
|
||||
let mut cargo_toml = match std::fs::File::open("./Cargo.toml") {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
error!("[ERROR] {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
set_var("ROOT", display_path(path));
|
||||
let ip = matches
|
||||
.value_of("address")
|
||||
.unwrap_or("127.0.0.1")
|
||||
.to_string();
|
||||
let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000"));
|
||||
let url = format!(
|
||||
"http://{}:{}/{}/index.html",
|
||||
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
|
||||
matches.value_of("port").unwrap_or("8000"),
|
||||
crate_name,
|
||||
);
|
||||
if !matches.is_present("noopen") {
|
||||
open_in_browser(&url);
|
||||
}
|
||||
addr
|
||||
} else {
|
||||
addr
|
||||
};
|
||||
set_var("LISTEN_ADDRESS", addr);
|
||||
|
||||
let mut contents = String::new();
|
||||
match cargo_toml.read_to_string(&mut contents) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
error!("[ERROR] {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let contents: CargoToml = match toml::from_str(&contents) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
error!("[ERROR] {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let crate_name = contents.package.name;
|
||||
info!("[INFO] Generating document (may take a while)");
|
||||
match std::process::Command::new("cargo").arg("doc").output() {
|
||||
Ok(output) => {
|
||||
let output = std::str::from_utf8(&output.stderr).unwrap_or("");
|
||||
if output.starts_with("error: could not find `Cargo.toml` in") {
|
||||
error!("[ERROR] Cargo.toml Not Found");
|
||||
return Ok(());
|
||||
} else if output.starts_with("error: ") {
|
||||
error!(
|
||||
"[ERROR] {}",
|
||||
output.strip_prefix("error: ").unwrap_or(output)
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("[ERROR] Cargo Error: {}", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let path = Path::new("./target/doc/");
|
||||
let mut index_path = path.to_path_buf();
|
||||
index_path.push(crate_name.to_string() + "/index.html");
|
||||
if !index_path.exists() || !index_path.is_file() {
|
||||
error!("[ERROR] Cargo Error: doc path not found");
|
||||
return Ok(());
|
||||
}
|
||||
set_var("ROOT", display_path(path));
|
||||
let ip = matches
|
||||
.value_of("address")
|
||||
.unwrap_or("127.0.0.1")
|
||||
.to_string();
|
||||
let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000"));
|
||||
let url = format!(
|
||||
"http://{}:{}/{}/index.html",
|
||||
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
|
||||
matches.value_of("port").unwrap_or("8000"),
|
||||
crate_name,
|
||||
);
|
||||
if !matches.is_present("noopen") {
|
||||
open_in_browser(&url);
|
||||
}
|
||||
addr
|
||||
} else {
|
||||
addr
|
||||
};
|
||||
set_var("LISTEN_ADDRESS", addr);
|
||||
|
||||
let server = HttpServer::new(move || {
|
||||
let app = App::new()
|
||||
.wrap_fn(|req, srv| {
|
||||
@ -733,7 +742,10 @@ async fn main() -> std::io::Result<()> {
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(cert, key)
|
||||
.expect("bad certificate/key");
|
||||
server.bind_rustls(var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()), config)
|
||||
server.bind_rustls(
|
||||
var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()),
|
||||
config,
|
||||
)
|
||||
} else {
|
||||
server.bind(var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()))
|
||||
};
|
||||
|
Reference in New Issue
Block a user