diff --git a/core/http/src/handling/response/datatypes.rs b/core/http/src/handling/response/datatypes.rs index 9225ced968351185e4ce286e48eb9b08e9f0b7aa..b8657ee781f15c8e97d5b544431a8a93f9dec0a2 100644 --- a/core/http/src/handling/response/datatypes.rs +++ b/core/http/src/handling/response/datatypes.rs @@ -27,6 +27,7 @@ pub enum Outcome<S, E, F> { } /// Response is a wrapper for http responses. +#[derive(Debug)] pub struct Response { /// the [`Vec<String>`] of headers unrelated to `Content-Type` and `Content-Length` pub headers: HeaderMap, diff --git a/core/http/src/handling/response/traits.rs b/core/http/src/handling/response/traits.rs index 6e96ddf50dca13976e8a3ffc4929dd7e25c47744..d3179a285f973d5ed80871c25478f852fbd78046 100644 --- a/core/http/src/handling/response/traits.rs +++ b/core/http/src/handling/response/traits.rs @@ -1,7 +1,9 @@ +use std::fmt::Debug; + use crate::{handling::routes::Body, utils::mime::Mime}; /// Trait for using datatypes as response bodies -pub trait ResponseBody: Send { +pub trait ResponseBody: Send + Debug { /// Get a cloned version of the data as a [`Vec<u8>`] /// # Ecamples /// ``` diff --git a/core/http/src/utils/mime/mime_enum.rs b/core/http/src/utils/mime/mime_enum.rs index 12c63d60e55c593c0ecc4544dae8c4ccc4f3dbfa..1ad81818e94d55b3d09dde93cf38f8aa4b3e6941 100644 --- a/core/http/src/utils/mime/mime_enum.rs +++ b/core/http/src/utils/mime/mime_enum.rs @@ -4084,6 +4084,7 @@ impl Mime { "json" => Mime::ApplicationJson, "html" => Mime::TextHtml, "css" => Mime::TextCss, + "svg" => Mime::ImageSvgXml, &_ => Mime::TextPlain, }, None => Mime::TextPlain, diff --git a/site/assets/favicon.svg b/site/assets/favicon.svg new file mode 100644 index 0000000000000000000000000000000000000000..b4d91476b910e4581810b8fc8924869a7a8f381f --- /dev/null +++ b/site/assets/favicon.svg @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> + +<svg + fill="#000000" + height="800px" + width="800px" + version="1.1" + id="Capa_1" + viewBox="0 0 511 511" + xml:space="preserve" + sodipodi:docname="favicon.svg" + inkscape:version="1.2.2 (b0a8486541, 2022-12-01)" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"><defs + id="defs290" /><sodipodi:namedview + id="namedview288" + pagecolor="#505050" + bordercolor="#eeeeee" + borderopacity="1" + inkscape:showpageshadow="0" + inkscape:pageopacity="0" + inkscape:pagecheckerboard="0" + inkscape:deskcolor="#505050" + showgrid="false" + inkscape:zoom="1.51125" + inkscape:cx="390.73615" + inkscape:cy="400" + inkscape:window-width="5120" + inkscape:window-height="1387" + inkscape:window-x="0" + inkscape:window-y="28" + inkscape:window-maximized="1" + inkscape:current-layer="Capa_1" /> +<g + id="g285" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1"> + <path + d="M487.5,128.106H479v-24.5c0-2.905-1.678-5.549-4.307-6.786C405.088,64.066,325.408,63.6,255.5,95.371 C185.592,63.6,105.912,64.067,36.307,96.82C33.678,98.057,32,100.701,32,103.606v24.5h-8.5c-12.958,0-23.5,10.542-23.5,23.5v264 c0,12.958,10.542,23.5,23.5,23.5h464c12.958,0,23.5-10.542,23.5-23.5v-264C511,138.648,500.458,128.106,487.5,128.106z M263,239.583c0-0.009,0-0.019,0-0.028V108.416c64.137-28.707,136.861-28.707,201,0v27.161c0,0.01-0.001,0.02-0.001,0.029 s0.001,0.02,0.001,0.029v244.438c-32.237-13.461-66.371-20.193-100.5-20.193c-34.129,0-68.264,6.732-100.5,20.193V239.583z M215,96.391c11.187,3.204,22.217,7.198,33,12.025v117.177l-12.34-8.227c-2.52-1.68-5.801-1.68-8.32,0L215,225.593V96.391z M47,135.626c0-0.007,0.001-0.013,0.001-0.02S47,135.594,47,135.587v-27.171c48.563-21.736,102.046-26.999,153-15.82v32.856 c-26.767-5.505-54.078-6.777-81.328-3.75c-4.117,0.457-7.083,4.165-6.626,8.282c0.458,4.116,4.162,7.085,8.282,6.626 c26.708-2.967,53.479-1.562,79.671,4.165v48.686c-15.912-3.265-32.14-5.067-48.377-5.323c-4.145-0.078-7.552,3.239-7.618,7.38 c-0.065,4.142,3.239,7.552,7.38,7.618c16.331,0.258,32.654,2.164,48.614,5.647v16.66c-43.389-8.909-88.39-6.644-130.748,6.665 c-3.952,1.241-6.148,5.451-4.907,9.403c1.007,3.204,3.964,5.254,7.153,5.254c0.745,0,1.502-0.112,2.25-0.347 c40.908-12.852,84.428-14.773,126.252-5.638v2.825c0,2.766,1.522,5.308,3.961,6.612c2.438,1.306,5.398,1.162,7.699-0.372 l19.84-13.227l16.5,11v136.454c-32.237-13.461-66.371-20.193-100.5-20.193c-34.129,0-68.264,6.732-100.5,20.193V135.626z M224,424.106H23.5c-4.687,0-8.5-3.813-8.5-8.5v-264c0-4.687,3.813-8.5,8.5-8.5H32v248.5v8c0,4.142,3.358,7.5,7.5,7.5H224V424.106z M57.29,392.106c58.099-22.934,122.32-22.935,180.42,0H57.29z M272,424.106h-33v-17h33V424.106z M453.71,392.106H273.29 C331.389,369.172,395.61,369.172,453.71,392.106z M496,415.606c0,4.687-3.813,8.5-8.5,8.5H287v-17h184.5c4.142,0,7.5-3.358,7.5-7.5 v-8v-248.5h8.5c4.687,0,8.5,3.813,8.5,8.5V415.606z" + id="path243" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M309.96,317.749c-8.302,1.74-16.615,3.911-24.708,6.454c-3.952,1.242-6.148,5.452-4.907,9.403 c1.007,3.204,3.964,5.254,7.153,5.254c0.745,0,1.502-0.112,2.25-0.347c7.628-2.396,15.464-4.443,23.288-6.083 c4.054-0.85,6.652-4.825,5.802-8.879C317.989,319.497,314.011,316.9,309.96,317.749z" + id="path245" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M439.502,338.859c3.189,0,6.147-2.051,7.153-5.254c1.241-3.952-0.956-8.162-4.907-9.403 c-32.073-10.076-65.329-13.842-98.844-11.188c-4.129,0.326-7.211,3.938-6.885,8.068s3.935,7.213,8.068,6.885 c31.59-2.499,62.935,1.048,93.165,10.546C438,338.748,438.757,338.859,439.502,338.859z" + id="path247" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M287.498,306.767c0.745,0,1.502-0.112,2.25-0.347c48.249-15.159,99.256-15.159,147.504,0 c3.952,1.24,8.162-0.956,9.403-4.907c1.241-3.952-0.956-8.162-4.907-9.403c-51.191-16.083-105.306-16.083-156.496,0 c-3.952,1.241-6.149,5.451-4.907,9.403C281.352,304.716,284.309,306.767,287.498,306.767z" + id="path249" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M287.498,274.859c0.745,0,1.502-0.112,2.25-0.347c27.681-8.697,56.409-12.412,85.399-11.037 c4.147,0.192,7.651-2.999,7.847-7.137c0.196-4.138-2.999-7.65-7.137-7.847c-30.753-1.456-61.236,2.483-90.605,11.71 c-3.952,1.242-6.149,5.452-4.907,9.403C281.352,272.81,284.309,274.859,287.498,274.859z" + id="path251" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M441.748,260.202c-10.76-3.38-21.846-6.086-32.952-8.043c-4.08-0.719-7.968,2.006-8.688,6.085 c-0.719,4.079,2.005,7.969,6.085,8.688c10.467,1.844,20.917,4.395,31.058,7.581c0.749,0.235,1.505,0.347,2.25,0.347 c3.189,0,6.147-2.051,7.153-5.254C447.896,265.653,445.7,261.443,441.748,260.202z" + id="path253" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M287.498,242.767c0.745,0,1.502-0.112,2.25-0.347c48.249-15.159,99.256-15.159,147.504,0 c3.952,1.24,8.162-0.956,9.403-4.907c1.241-3.952-0.956-8.162-4.907-9.403c-51.191-16.083-105.306-16.083-156.496,0 c-3.952,1.241-6.149,5.451-4.907,9.403C281.352,240.716,284.309,242.767,287.498,242.767z" + id="path255" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M334.678,185.702c-16.732,1.858-33.362,5.36-49.426,10.407c-3.952,1.241-6.148,5.451-4.907,9.403 c1.007,3.204,3.964,5.254,7.153,5.254c0.745,0,1.502-0.112,2.25-0.347c15.141-4.757,30.815-8.057,46.585-9.809 c4.117-0.457,7.083-4.165,6.626-8.282S338.79,185.244,334.678,185.702z" + id="path257" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M367.386,199.137c23.725,0.375,47.231,4.17,69.866,11.283c0.748,0.234,1.505,0.347,2.25,0.347 c3.189,0,6.146-2.051,7.153-5.254c1.241-3.952-0.956-8.162-4.907-9.403c-24.015-7.545-48.955-11.572-74.125-11.97 c-4.125-0.078-7.552,3.239-7.618,7.38S363.244,199.072,367.386,199.137z" + id="path259" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M390.671,168.704c4.116,0.46,7.825-2.509,8.282-6.626c0.458-4.117-2.509-7.825-6.626-8.282 c-36.252-4.027-72.278-0.526-107.075,10.406c-3.952,1.242-6.148,5.452-4.907,9.403c1.007,3.204,3.964,5.254,7.153,5.254 c0.745,0,1.502-0.112,2.25-0.347C322.545,168.208,356.5,164.909,390.671,168.704z" + id="path261" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M441.748,164.202c-5.418-1.702-10.96-3.246-16.472-4.588c-4.03-0.98-8.082,1.488-9.062,5.512 c-0.98,4.024,1.488,8.082,5.512,9.062c5.196,1.265,10.419,2.72,15.526,4.324c0.748,0.235,1.505,0.347,2.25,0.347 c3.189,0,6.147-2.051,7.153-5.254C447.896,169.653,445.7,165.443,441.748,164.202z" + id="path263" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M287.498,146.767c0.745,0,1.502-0.112,2.25-0.347c5.103-1.604,10.325-3.058,15.521-4.324 c4.024-0.98,6.492-5.037,5.512-9.062s-5.038-6.492-9.062-5.512c-5.513,1.342-11.053,2.886-16.468,4.587 c-3.951,1.242-6.148,5.452-4.907,9.403C281.352,144.716,284.309,146.767,287.498,146.767z" + id="path265" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M336.329,136.611c34.172-3.796,68.126-0.496,100.923,9.809c0.748,0.234,1.505,0.347,2.25,0.347 c3.189,0,6.146-2.051,7.153-5.254c1.241-3.952-0.956-8.162-4.907-9.403c-34.797-10.933-70.824-14.435-107.076-10.406 c-4.117,0.457-7.083,4.165-6.626,8.282C328.504,134.102,332.21,137.07,336.329,136.611z" + id="path267" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M93.96,317.749c-8.302,1.74-16.615,3.911-24.708,6.454c-3.952,1.242-6.148,5.452-4.907,9.403 c1.007,3.204,3.964,5.254,7.153,5.254c0.745,0,1.502-0.112,2.25-0.347c7.628-2.396,15.464-4.443,23.288-6.083 c4.054-0.85,6.652-4.825,5.802-8.879S98.011,316.9,93.96,317.749z" + id="path269" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M223.502,338.859c3.189,0,6.147-2.051,7.153-5.254c1.241-3.952-0.956-8.162-4.907-9.403 c-32.073-10.076-65.331-13.842-98.844-11.188c-4.129,0.326-7.211,3.938-6.885,8.068s3.934,7.213,8.068,6.885 c31.591-2.499,62.935,1.048,93.165,10.546C222,338.748,222.757,338.859,223.502,338.859z" + id="path271" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M71.498,306.767c0.745,0,1.502-0.112,2.25-0.347c48.249-15.159,99.256-15.159,147.504,0 c3.952,1.24,8.162-0.956,9.403-4.907c1.241-3.952-0.956-8.162-4.907-9.403c-51.191-16.083-105.307-16.083-156.496,0 c-3.952,1.241-6.149,5.451-4.907,9.403C65.352,304.716,68.309,306.767,71.498,306.767z" + id="path273" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M71.498,274.859c0.745,0,1.502-0.112,2.25-0.347c27.681-8.697,56.411-12.412,85.399-11.037 c4.158,0.192,7.65-2.999,7.847-7.137c0.196-4.138-2.999-7.65-7.137-7.847c-30.756-1.456-61.236,2.483-90.605,11.71 c-3.952,1.242-6.149,5.452-4.907,9.403C65.352,272.81,68.309,274.859,71.498,274.859z" + id="path275" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M190.194,266.932c10.467,1.844,20.917,4.395,31.058,7.581c0.749,0.235,1.505,0.347,2.25,0.347 c3.189,0,6.147-2.051,7.153-5.254c1.241-3.952-0.956-8.162-4.907-9.403c-10.76-3.38-21.846-6.086-32.952-8.043 c-4.079-0.719-7.969,2.006-8.688,6.085C183.39,262.323,186.114,266.213,190.194,266.932z" + id="path277" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M118.678,185.702c-16.732,1.858-33.362,5.36-49.426,10.407c-3.952,1.241-6.148,5.451-4.907,9.403 c1.007,3.204,3.964,5.254,7.153,5.254c0.745,0,1.502-0.112,2.25-0.347c15.141-4.757,30.815-8.057,46.585-9.809 c4.117-0.457,7.083-4.165,6.626-8.282C126.503,188.212,122.788,185.244,118.678,185.702z" + id="path279" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M64.345,173.605c1.007,3.204,3.964,5.254,7.153,5.254c0.745,0,1.502-0.112,2.25-0.347 c32.797-10.305,66.752-13.604,100.923-9.809c4.116,0.46,7.825-2.509,8.282-6.626c0.458-4.117-2.509-7.825-6.626-8.282 c-36.253-4.027-72.278-0.526-107.075,10.406C65.3,165.444,63.104,169.654,64.345,173.605z" + id="path281" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> + <path + d="M71.498,146.767c0.745,0,1.502-0.112,2.25-0.347c5.103-1.604,10.325-3.058,15.521-4.324 c4.024-0.98,6.492-5.037,5.512-9.062s-5.038-6.492-9.062-5.512c-5.513,1.342-11.053,2.886-16.468,4.587 c-3.951,1.242-6.148,5.452-4.907,9.403C65.352,144.716,68.309,146.767,71.498,146.767z" + id="path283" + style="stroke:#ffffff;stroke-opacity:1;fill:#ffffff;fill-opacity:1" /> +</g> +</svg> diff --git a/site/hello.css b/site/hello.css deleted file mode 100644 index aba0df0603e473b6811c64f41e53ebd3559100d9..0000000000000000000000000000000000000000 --- a/site/hello.css +++ /dev/null @@ -1,4 +0,0 @@ -body { - background-color: #212121; - color: #ffffff; -} diff --git a/site/img.jpg b/site/img.jpg deleted file mode 100644 index 07eb7f85ac26c70344d552f56a81c44a0bf1b3db..0000000000000000000000000000000000000000 Binary files a/site/img.jpg and /dev/null differ diff --git a/site/src/main.rs b/site/src/main.rs index c4b515a2aa4d3fcb2d347f6a247b6d15f55f4e4e..3520b3bd3c4dd083cea7c153cd36180312dff64f 100644 --- a/site/src/main.rs +++ b/site/src/main.rs @@ -1,5 +1,23 @@ use http::handling::{methods::Method, routes::{Route, Data}, request::Request, response::{Response, Outcome, Status}, file_handlers::NamedFile}; +fn static_files_handler(request: Request<>, _data: Data) -> Outcome<Response, Status, Data> { + let response = static_files(request.uri.raw_string().unwrap()); + let response = match response { + Ok(dat) => Response { + headers: vec![], + cookies: None, + status: Some(Status::Ok), + body: Box::new(dat), + }, + Err(_) => return Outcome::Failure(Status::NotFound), + }; + Outcome::Success(response) +} + +fn static_files(path: &str) -> Result<NamedFile, Status> { + NamedFile::open(("static/".to_string() + path).into()) +} + fn index_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> { Outcome::Success(Response { headers: vec![], cookies: None, status: None, body: Box::new(index()) }) } @@ -8,21 +26,50 @@ fn index() -> NamedFile { NamedFile::open("templates/index.html".into()).unwrap() } +fn favicon_handler(_request: Request, _data: Data) -> Outcome<Response, Status, Data> { + let response = Response { + headers: vec![], + cookies: None, + status: None, + body: Box::new(NamedFile::open("/assets/favicon.svg".into()).unwrap()) + }; + Outcome::Success(response) +} + #[tokio::main] async fn main() { let index_route = Route { format: None, handler: index_handler, - name: Some("Index"), + name: Some("index"), uri: "", method: Method::Get, rank: 0, }; + let static_route = Route { + format: None, + handler: static_files_handler, + name: Some("static files"), + uri: "", + method: Method::Get, + rank: 0 + }; + + let favicon = Route { + format: None, + handler: favicon_handler, + name: Some("favicon"), + uri: "favicon.ico", + method: Method::Get, + rank: 0 + }; + // http::build("127.0.0.1:8000") http::build("127.0.0.1:8443", "127.0.0.1:8080") .await - .mount("/", vec![index_route]) + .mount("/", vec![index_route, favicon]) + .mount("/static", vec![static_route]) .launch() .await; } diff --git a/site/static/hello.html b/site/static/hello.html deleted file mode 100644 index bf12019a992d72484315f1250c4488fba1638b0d..0000000000000000000000000000000000000000 --- a/site/static/hello.html +++ /dev/null @@ -1,12 +0,0 @@ -<!doctype html> -<html> - <head> - <meta charset="UTF-8" /> - <title>Hello</title> - <link rel="stylesheet" href="/static/style.css" /> - </head> - <body> - <h1>Managed</h1> - <img src="/static/img.jpg" alt="" /> - </body> -</html> diff --git a/site/static/hi b/site/static/hi deleted file mode 100644 index 8bd6648ed130ac9ece0f89cd9a8fbbfd2608427a..0000000000000000000000000000000000000000 --- a/site/static/hi +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/site/static/img.jpg b/site/static/img.jpg deleted file mode 100644 index 07eb7f85ac26c70344d552f56a81c44a0bf1b3db..0000000000000000000000000000000000000000 Binary files a/site/static/img.jpg and /dev/null differ diff --git a/site/templates/index.html b/site/templates/index.html index 8645f34c319e16a7249b334f8fa955a3fdd6ed01..7dc2842858c99981c04ebbb86641ad3a0f15d7e6 100644 --- a/site/templates/index.html +++ b/site/templates/index.html @@ -6,6 +6,16 @@ <link rel="stylesheet" href="/static/style.css" /> </head> <body> - <h1>Hello and Welcome</h1> + <header> + <nav> + <div>LOGO</div> + <div> + <div>Dashboard</div> + <div>Books</div> + <div>Magazines</div> + <div>Newspapers</div> + </div> + </nav> + </header> </body> </html>