dev: misc improve here and there
This commit is contained in:
@@ -44,6 +44,11 @@ pub const ERROR_ASCII_ARTS: &[&str] = &[
|
|||||||
include_str!("../assets/lain/lain-teddy.txt"),
|
include_str!("../assets/lain/lain-teddy.txt"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub mod mime {
|
||||||
|
pub const TEXT: &str = "text/plain; charset=utf-8";
|
||||||
|
pub const HTML: &str = "text/html; charset=utf-8";
|
||||||
|
}
|
||||||
|
|
||||||
pub mod web_scopes {
|
pub mod web_scopes {
|
||||||
pub const IMAGES: &str = "/image";
|
pub const IMAGES: &str = "/image";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use actix_web::{App, HttpServer, web};
|
use actix_web::{App, HttpServer, middleware, web};
|
||||||
|
|
||||||
pub mod caches;
|
pub mod caches;
|
||||||
pub mod services;
|
pub mod services;
|
||||||
@@ -38,9 +38,8 @@ pub async fn start_app(args: crate::args::Args, config: crate::conf::Config) ->
|
|||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(app)
|
.app_data(app)
|
||||||
.wrap(actix_web::middleware::Logger::new(
|
.wrap(middleware::Logger::new("%a (%{r}a) %r -> %s, %b B in %T s"))
|
||||||
"%a (%{r}a) %r -> %s, %b B in %T s",
|
.wrap(middleware::NormalizePath::trim())
|
||||||
))
|
|
||||||
.service(services::images::make_scope(ws::IMAGES))
|
.service(services::images::make_scope(ws::IMAGES))
|
||||||
.default_service(web::to(services::not_found::not_found))
|
.default_service(web::to(services::not_found::not_found))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ pub async fn not_found(req: HttpRequest) -> HttpResponse {
|
|||||||
let url = req.path();
|
let url = req.path();
|
||||||
|
|
||||||
HttpResponse::NotFound()
|
HttpResponse::NotFound()
|
||||||
.content_type("text/plain; charset=utf-8")
|
.content_type(consts::mime::TEXT)
|
||||||
.streaming(stream::iter([
|
.streaming(stream::iter([
|
||||||
Ok::<_, !>(web::Bytes::from(format!(
|
Ok::<_, !>(web::Bytes::from(format!(
|
||||||
"> {method} '{url}'\n404 NOT FOUND\nLet's all love lain\n\n"
|
"> {method} '{url}'\n404 NOT FOUND\nLet's all love lain\n\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user