-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stéphan Kochen
committed
Aug 7, 2017
1 parent
c73c830
commit a8808b2
Showing
13 changed files
with
541 additions
and
673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
language: rust | ||
rust: nightly | ||
after_success: 'curl https://raw.githubusercontent.com/iron/build-doc/master/build-doc.sh | sh ' | ||
rust: | ||
- stable | ||
- nightly |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
[package] | ||
|
||
name = "staticfile" | ||
version = "0.4.0" | ||
authors = ["Zach Pomerantz <[email protected]>", "Jonathan Reem <[email protected]>"] | ||
description = "Static file serving for Iron." | ||
repository = "https://github.com/iron/staticfile" | ||
name = "hyper-staticfile" | ||
version = "0.1.0" | ||
authors = [ | ||
"Zach Pomerantz <[email protected]>", | ||
"Jonathan Reem <[email protected]>", | ||
"Stéphan Kochen <[email protected]>", | ||
] | ||
description = "Static file serving for Hyper 0.11" | ||
repository = "https://github.com/stephank/hyper-staticfile" | ||
license = "MIT" | ||
keywords = ["iron", "web", "http", "file"] | ||
|
||
[features] | ||
cache = ["filetime"] | ||
keywords = ["hyper", "web", "http", "file"] | ||
|
||
[dependencies] | ||
iron = "0.5" | ||
mount = "0.3" | ||
time = "0.1" | ||
futures = "0.1" | ||
hyper = "0.11" | ||
tokio-core = "0.1" | ||
url = "1.1" | ||
|
||
[dependencies.filetime] | ||
version = "0.1" | ||
optional = true | ||
|
||
[dev-dependencies] | ||
hyper = "0.10" | ||
router = "0.5" | ||
iron-test = "0.5" | ||
tempdir = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,7 @@ | ||
staticfile [![Build Status](https://secure.travis-ci.org/iron/staticfile.png?branch=master)](https://travis-ci.org/iron/staticfile) | ||
==== | ||
# hyper-staticfile [![Build Status](https://secure.travis-ci.org/stephank/hyper-staticfile.png?branch=master)](https://travis-ci.org/stephank/hyper-staticfile) | ||
|
||
> Static file-serving handler for the [Iron](https://github.com/iron/iron) web framework. | ||
## Example | ||
|
||
This example uses the [mounting handler][mounting-handler] to serve files from several directories. | ||
|
||
```rust | ||
let mut mount = Mount::new(); | ||
|
||
// Serve the shared JS/CSS at / | ||
mount.mount("/", Static::new(Path::new("target/doc/"))); | ||
// Serve the static file docs at /doc/ | ||
mount.mount("/doc/", Static::new(Path::new("target/doc/staticfile/"))); | ||
// Serve the source code at /src/ | ||
mount.mount("/src/", Static::new(Path::new("target/doc/src/staticfile/lib.rs.html"))); | ||
|
||
Iron::new(mount).http("127.0.0.1:3000").unwrap(); | ||
``` | ||
Static file-serving for [Hyper 0.11](https://github.com/hyperium/hyper). | ||
|
||
See [`examples/doc_server.rs`](examples/doc_server.rs) for a complete example that you can compile. | ||
|
||
## Overview | ||
|
||
- Serve static files from a given path. | ||
|
||
It works well in combination with the [mounting handler][mounting-handler]. | ||
|
||
## Installation | ||
|
||
If you're using a `Cargo.toml` to manage dependencies, just add the `staticfile` package to the `[dependencies]` section of the toml: | ||
|
||
```toml | ||
staticfile = "*" | ||
``` | ||
|
||
Otherwise, `cargo build`, and the rlib will be in your `target` directory. | ||
|
||
## [Documentation](http://ironframework.io/doc/staticfile) | ||
|
||
Along with the [online documentation](http://ironframework.io/doc/staticfile), | ||
you can build a local copy with `cargo doc`. | ||
|
||
## Get Help | ||
|
||
One of us ([@reem](https://github.com/reem/), [@zzmp](https://github.com/zzmp/), | ||
[@theptrk](https://github.com/theptrk/), [@mcreinhard](https://github.com/mcreinhard)) | ||
is usually on `#iron` on the mozilla irc. Come say hi and ask any questions you might have. | ||
We are also usually on `#rust` and `#rust-webdev`. | ||
|
||
[mounting-handler]: https://github.com/iron/mount | ||
## [Documentation](http://docs.rs/hyper-staticfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,64 @@ | ||
extern crate iron; | ||
extern crate staticfile; | ||
extern crate mount; | ||
extern crate futures; | ||
extern crate hyper; | ||
extern crate hyper_staticfile; | ||
extern crate tokio_core; | ||
|
||
// This example serves the docs from target/doc/staticfile at /doc/ | ||
// | ||
// Run `cargo doc && cargo run --example doc_server`, then | ||
// point your browser to http://127.0.0.1:3000/doc/ | ||
// point your browser to http://localhost:3000/ | ||
|
||
use futures::{Future, BoxFuture, Stream, future}; | ||
use hyper::server::{Http, Request, Response, Service}; | ||
use hyper_staticfile::Static; | ||
use std::path::Path; | ||
use tokio_core::reactor::{Core, Handle}; | ||
use tokio_core::net::{TcpListener}; | ||
|
||
use iron::Iron; | ||
use staticfile::Static; | ||
use mount::Mount; | ||
struct MainService { | ||
static_: Static, | ||
} | ||
|
||
impl MainService { | ||
fn new(handle: &Handle) -> MainService { | ||
MainService { | ||
static_: Static::new(handle, Path::new("target/doc/")), | ||
} | ||
} | ||
} | ||
|
||
impl Service for MainService { | ||
type Request = Request; | ||
type Response = Response; | ||
type Error = hyper::Error; | ||
type Future = BoxFuture<Self::Response, Self::Error>; | ||
|
||
fn call(&self, req: Request) -> Self::Future { | ||
if req.path() == "/" { | ||
let res = Response::new() | ||
.with_status(hyper::StatusCode::MovedPermanently) | ||
.with_header(hyper::header::Location::new("/hyper_staticfile/")); | ||
future::ok(res).boxed() | ||
} else { | ||
Service::call(&self.static_, req) | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut mount = Mount::new(); | ||
let mut core = Core::new().unwrap(); | ||
let handle = core.handle(); | ||
|
||
// Serve the shared JS/CSS at / | ||
mount.mount("/", Static::new(Path::new("target/doc/"))); | ||
// Serve the static file docs at /doc/ | ||
mount.mount("/doc/", Static::new(Path::new("target/doc/staticfile/"))); | ||
// Serve the source code at /src/ | ||
mount.mount("/src/", Static::new(Path::new("target/doc/src/staticfile/lib.rs.html"))); | ||
let addr = "127.0.0.1:3000".parse().unwrap(); | ||
let listener = TcpListener::bind(&addr, &handle).unwrap(); | ||
|
||
println!("Doc server running on http://localhost:3000/doc/"); | ||
let http = Http::new(); | ||
let server = listener.incoming().for_each(|(sock, addr)| { | ||
let s = MainService::new(&handle); | ||
http.bind_connection(&handle, sock, addr, s); | ||
Ok(()) | ||
}); | ||
|
||
Iron::new(mount).http("127.0.0.1:3000").unwrap(); | ||
println!("Doc server running on http://localhost:3000/"); | ||
core.run(server).unwrap(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
#![crate_name = "staticfile"] | ||
#![crate_name = "hyper_staticfile"] | ||
#![deny(missing_docs)] | ||
#![deny(warnings)] | ||
|
||
//! Static file-serving handler. | ||
//! Static file-serving for [Hyper 0.11](https://github.com/hyperium/hyper). | ||
extern crate time; | ||
|
||
#[cfg(feature = "cache")] | ||
extern crate filetime; | ||
|
||
extern crate iron; | ||
extern crate mount; | ||
extern crate futures; | ||
extern crate hyper; | ||
extern crate tokio_core; | ||
extern crate url; | ||
|
||
pub use static_handler::Static; | ||
#[cfg(feature = "cache")] | ||
pub use static_handler::Cache; | ||
|
||
mod requested_path; | ||
mod static_handler; | ||
mod static_service; | ||
|
||
pub use static_service::Static; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.