2020-09-12 16:21:54 +01:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2019-06-17 16:57:57 -04:00
|
|
|
// <error-handler>
|
|
|
|
use actix_web::middleware::errhandlers::{ErrorHandlerResponse, ErrorHandlers};
|
2019-06-26 02:59:20 -04:00
|
|
|
use actix_web::{dev, http, HttpResponse, Result};
|
2019-06-17 16:57:57 -04:00
|
|
|
|
|
|
|
fn render_500<B>(mut res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> {
|
|
|
|
res.response_mut().headers_mut().insert(
|
|
|
|
http::header::CONTENT_TYPE,
|
|
|
|
http::HeaderValue::from_static("Error"),
|
|
|
|
);
|
|
|
|
Ok(ErrorHandlerResponse::Response(res))
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 02:03:17 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-26 02:59:20 -04:00
|
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
|
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
|
|
|
.wrap(
|
|
|
|
ErrorHandlers::new()
|
|
|
|
.handler(http::StatusCode::INTERNAL_SERVER_ERROR, render_500),
|
|
|
|
)
|
|
|
|
.service(
|
|
|
|
web::resource("/test")
|
|
|
|
.route(web::get().to(|| HttpResponse::Ok()))
|
|
|
|
.route(web::head().to(|| HttpResponse::MethodNotAllowed())),
|
|
|
|
)
|
|
|
|
})
|
2020-09-12 16:21:54 +01:00
|
|
|
.bind("127.0.0.1:8080")?
|
2019-06-26 02:59:20 -04:00
|
|
|
.run()
|
2019-12-29 02:03:17 +09:00
|
|
|
.await
|
2019-06-17 16:57:57 -04:00
|
|
|
}
|
|
|
|
// </error-handler>
|