agate

Simple gemini server for static files
git clone https://github.com/mbrubeck/agate.git
Log | Files | Refs | README

commit db0785c4b9de2a7c9e4244f84af2185a74177042
parent d6cb2e831b68497610afe63d93a978ed92a824d5
Author: Matt Brubeck <mbrubeck@limpet.net>
Date:   Wed, 20 May 2020 08:10:50 -0700

Use index.gemini instead of dir listings

Diffstat:
Msrc/main.rs | 27+++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -11,7 +11,7 @@ use { error::Error, fs::{File, read}, io::BufReader, - path::{Path, PathBuf}, + path::PathBuf, sync::Arc, }, url::Url, @@ -106,26 +106,9 @@ fn get(url: &Url) -> Result<Vec<u8>> { Err("invalid path")? } eprintln!("Got request for {:?}", path); - let response = if path.is_dir() { - list(&path)? - } else { - read(&path)? - }; - Ok(response) -} - -fn list(path: &Path) -> Result<Vec<u8>> { - use std::io::Write; - let mut result = vec![]; - for entry in path.read_dir()? { - let entry = entry?; - let file_name = entry.file_name().into_string() - .or(Err("non-Unicode path"))?; - let path = entry.path(); - let url = path.strip_prefix(&ARGS.content_dir)?.to_str() - .ok_or("non-Unicode path")?; - // TODO: Escape whitespace - writeln!(&mut result, "=> {} {}", url, file_name)?; + if path.is_dir() { + path.push("index.gemini"); } - Ok(result) + let response = read(&path)?; + Ok(response) }