summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-07-19 10:32:08 +0000
committerLars Wirzenius <liw@liw.fi>2020-07-19 10:32:08 +0000
commitf06b0bccfdb7459be0947a6fd6f726eba4bcf92d (patch)
tree7fafc5f2d22eaf68c9dcfea5a74fe03d6b0676c8 /src/main.rs
parentf1590591451f135ca903e20f24ca5a9d0e7fba14 (diff)
parentb130e74f187b2ba22db6654508a6e7e4c721a16e (diff)
downloadewww-f06b0bccfdb7459be0947a6fd6f726eba4bcf92d.tar.gz
Merge branch 'serve-files' into 'master'
Serve files See merge request larswirzenius/ewww!7
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index d74a148..37e60d2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ use warp::Filter;
#[derive(Debug, Deserialize)]
struct Config {
+ webroot: PathBuf,
port: u16,
tls_key: PathBuf,
tls_cert: PathBuf,
@@ -19,6 +20,9 @@ struct Opt {
#[derive(Debug, thiserror::Error)]
enum EwwwError {
+ #[error("Web root {0} does not exist")]
+ WebrootNotFound(PathBuf),
+
#[error("TLS certificate {0} does not exist")]
TlsCertNotFound(PathBuf),
@@ -33,11 +37,12 @@ async fn main() {
let opt = Opt::from_args();
let config = read_config(&opt.config).unwrap();
- let hello = warp::any()
- .map(|| "hello, world\n".to_string());
+ let webroot = config.webroot.canonicalize().unwrap();
+ eprintln!("webroot: {:?}", webroot);
+ let webroot = warp::any().and(warp::fs::dir(webroot));
eprintln!("starting server: {:?}", config);
- warp::serve(hello)
+ warp::serve(webroot)
.tls()
.key_path(config.tls_key)
.cert_path(config.tls_cert)
@@ -53,6 +58,9 @@ fn read_config(filename: &Path) -> anyhow::Result<Config> {
}
fn check_config(config: &Config) -> anyhow::Result<()> {
+ if !config.webroot.exists() {
+ return Err(EwwwError::WebrootNotFound(config.webroot.clone()).into());
+ }
if !config.tls_cert.exists() {
return Err(EwwwError::TlsCertNotFound(config.tls_cert.clone()).into());
}