aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/sersve.rs32
2 files changed, 32 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
deleted file mode 100644
index a93251b..0000000
--- a/src/lib.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-#[test]
-fn it_works() {
-}
diff --git a/src/sersve.rs b/src/sersve.rs
new file mode 100644
index 0000000..ad7f001
--- /dev/null
+++ b/src/sersve.rs
@@ -0,0 +1,32 @@
+#![feature(globs, slicing_syntax)]
+
+extern crate iron;
+
+use std::os;
+use std::path::{ Path, GenericPath };
+use std::io::fs::{ File, PathExtensions };
+
+use iron::prelude::*;
+use iron::response::modifiers::*;
+use iron::status;
+
+fn text(desc: &str) -> IronResult<Response> {
+ Ok(Response::new().set(Status(status::Ok)).set(Body(desc)))
+}
+
+fn serve(req: &mut Request) -> IronResult<Response> {
+ let mut path = os::getcwd().ok().unwrap();
+ for part in req.url.path.iter() { path.push(part[]) }
+ if !path.exists() { return text("404"); } //Ok(Response::new().set(Status(status::NotFound))); }
+
+ let content = match File::open(&path).read_to_string() {
+ Ok(s) => s,
+ Err(e) => return text(e.desc)
+ };
+
+ text(content[])
+}
+
+fn main() {
+ Iron::new(serve).listen("127.0.0.1:80").unwrap();
+}