2019-06-19 06:20:50 +02:00
|
|
|
use actix_web::App;
|
2019-06-17 19:46:21 +02:00
|
|
|
// <recommend-two>
|
2019-06-19 06:20:50 +02:00
|
|
|
use actix_web::{error, fs, http, HttpRequest, HttpResponse};
|
2019-06-17 19:46:21 +02:00
|
|
|
use failure::Fail;
|
|
|
|
|
|
|
|
#[derive(Fail, Debug)]
|
|
|
|
enum UserError {
|
|
|
|
#[fail(display = "An internal error occurred. Please try again later.")]
|
|
|
|
InternalError,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::ResponseError for UserError {
|
|
|
|
fn error_response(&self) -> HttpResponse {
|
|
|
|
match *self {
|
|
|
|
UserError::InternalError => {
|
|
|
|
HttpResponse::new(http::StatusCode::INTERNAL_SERVER_ERROR)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn index(_req: HttpRequest) -> Result<&'static str, UserError> {
|
|
|
|
fs::NamedFile::open("static/index.html").map_err(|_e| UserError::InternalError)?;
|
|
|
|
Ok("success!")
|
|
|
|
}
|
|
|
|
// </recommend-two>
|
2019-06-19 06:20:50 +02:00
|
|
|
pub fn main() {
|
|
|
|
App::new().route("/", web::get().to(index));
|
|
|
|
}
|