update dependencies and fix deprecations
This commit is contained in:
@@ -1,26 +1,32 @@
|
||||
use actix_files::NamedFile;
|
||||
use actix_web::{dev, middleware::ErrorHandlerResponse, Result};
|
||||
use actix_web::{dev, middleware::ErrorHandlerResponse, Responder as _, Result};
|
||||
|
||||
pub fn bad_request<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> {
|
||||
let new_resp = NamedFile::open("static/errors/400.html")?
|
||||
.set_status_code(res.status())
|
||||
.into_response(res.request())
|
||||
.customize()
|
||||
.with_status(actix_web::http::StatusCode::OK)
|
||||
.respond_to(res.request())
|
||||
.map_into_boxed_body()
|
||||
.map_into_right_body();
|
||||
Ok(ErrorHandlerResponse::Response(res.into_response(new_resp)))
|
||||
}
|
||||
|
||||
pub fn not_found<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> {
|
||||
let new_resp = NamedFile::open("static/errors/404.html")?
|
||||
.set_status_code(res.status())
|
||||
.into_response(res.request())
|
||||
.customize()
|
||||
.with_status(actix_web::http::StatusCode::OK)
|
||||
.respond_to(res.request())
|
||||
.map_into_boxed_body()
|
||||
.map_into_right_body();
|
||||
Ok(ErrorHandlerResponse::Response(res.into_response(new_resp)))
|
||||
}
|
||||
|
||||
pub fn internal_server_error<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> {
|
||||
let new_resp = NamedFile::open("static/errors/500.html")?
|
||||
.set_status_code(res.status())
|
||||
.into_response(res.request())
|
||||
.customize()
|
||||
.with_status(actix_web::http::StatusCode::OK)
|
||||
.respond_to(res.request())
|
||||
.map_into_boxed_body()
|
||||
.map_into_right_body();
|
||||
Ok(ErrorHandlerResponse::Response(res.into_response(new_resp)))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
use std::io::Read as _;
|
||||
|
||||
use actix_files::NamedFile;
|
||||
use actix_web::{
|
||||
body::MessageBody,
|
||||
dev::{self, ServiceResponse},
|
||||
middleware::ErrorHandlerResponse,
|
||||
Responder, Result,
|
||||
};
|
||||
|
||||
pub fn bad_request<B: MessageBody>(
|
||||
mut res: dev::ServiceResponse<B>,
|
||||
) -> Result<ErrorHandlerResponse<B>> {
|
||||
let mut new_resp = NamedFile::open("static/errors/400.html")?;
|
||||
let mut body = String::new();
|
||||
new_resp.read_to_string(&mut body);
|
||||
|
||||
res.response_mut().set_body(body);
|
||||
|
||||
/* let (req, res) = res.into_parts();
|
||||
res.set_body(body);
|
||||
|
||||
let response = ServiceResponse::new(req, res)
|
||||
.map_into_boxed_body()
|
||||
.map_into_right_body(); */
|
||||
|
||||
Ok(ErrorHandlerResponse::Response(
|
||||
res.map_into_boxed_body().map_into_right_body(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn not_found<B>(res: dev::ServiceResponse<B>) -> Result<impl Responder> {
|
||||
let new_resp = NamedFile::open("static/errors/404.html")?
|
||||
.customize()
|
||||
.with_status(res.status())
|
||||
.respond_to(res.request());
|
||||
|
||||
Ok(new_resp)
|
||||
}
|
||||
|
||||
pub fn internal_server_error<B: MessageBody>(
|
||||
res: dev::ServiceResponse<B>,
|
||||
) -> Result<ErrorHandlerResponse<B>> {
|
||||
let mut new_resp = NamedFile::open("static/errors/500.html")?;
|
||||
let mut body = String::new();
|
||||
new_resp.read_to_string(&mut body);
|
||||
let (req, res) = res.into_parts();
|
||||
res.set_body(body);
|
||||
|
||||
let response = ServiceResponse::new(req, res)
|
||||
.map_into_boxed_body()
|
||||
.map_into_right_body();
|
||||
|
||||
Ok(ErrorHandlerResponse::Response(response))
|
||||
}
|
||||
@@ -7,11 +7,11 @@ use actix_web::{
|
||||
web, App, HttpServer,
|
||||
};
|
||||
use dotenv::dotenv;
|
||||
use handlebars::Handlebars;
|
||||
use handlebars::{DirectorySourceOptions, Handlebars};
|
||||
use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor};
|
||||
use log::debug;
|
||||
use std::env;
|
||||
use terminwahl_back::{api, db, handlebars_helper::TimeOfDate, views, CssPath};
|
||||
use terminwahl_back::{api, db, views, CssPath};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
@@ -40,9 +40,12 @@ async fn main() -> std::io::Result<()> {
|
||||
.build();
|
||||
|
||||
let mut handlebars = Handlebars::new();
|
||||
handlebars.register_helper("time_of", Box::new(TimeOfDate));
|
||||
let handlebars_source = DirectorySourceOptions {
|
||||
tpl_extension: ".hbs".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
handlebars
|
||||
.register_templates_directory(".hbs", handlebars_templates)
|
||||
.register_templates_directory(handlebars_templates, handlebars_source)
|
||||
.unwrap();
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
Reference in New Issue
Block a user