Added an "ip" page
This commit is contained in:
13
assets/css/ip.css
Normal file
13
assets/css/ip.css
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.ip {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ip h1 {
|
||||||
|
font-family: 'Indie Flower', cursive;
|
||||||
|
font-size: 60px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--clr-primary-a60);
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ use middleware::MimeType;
|
|||||||
use pages::{
|
use pages::{
|
||||||
files::file,
|
files::file,
|
||||||
index,
|
index,
|
||||||
|
ip::ip,
|
||||||
music::music,
|
music::music,
|
||||||
projects::{project, projects},
|
projects::{project, projects},
|
||||||
};
|
};
|
||||||
@@ -111,7 +112,8 @@ async fn main() {
|
|||||||
.service(index)
|
.service(index)
|
||||||
.service(projects)
|
.service(projects)
|
||||||
.service(project)
|
.service(project)
|
||||||
.service(music),
|
.service(music)
|
||||||
|
.service(ip),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.bind(bind_address)
|
.bind(bind_address)
|
||||||
@@ -119,7 +121,7 @@ async fn main() {
|
|||||||
match server.run().await {
|
match server.run().await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("An error occurred: {e}");
|
println!("An error occurred: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/pages/ip.rs
Normal file
34
src/pages/ip.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
use crate::html::elements::{Heading, Link};
|
||||||
|
use crate::html::layouts::Division;
|
||||||
|
use crate::html::pages::BasePage;
|
||||||
|
use crate::html::{Render, boxed_vec};
|
||||||
|
use actix_web::HttpRequest;
|
||||||
|
use actix_web::{Responder, get};
|
||||||
|
|
||||||
|
#[get("/ip")]
|
||||||
|
async fn ip(request: HttpRequest) -> impl Responder {
|
||||||
|
let info = request.connection_info();
|
||||||
|
let ip = info.realip_remote_addr();
|
||||||
|
|
||||||
|
let text = Heading::builder()
|
||||||
|
.text(format!(
|
||||||
|
"Your IP address is {}<br>Don't ask how I know.",
|
||||||
|
ip.unwrap_or("?")
|
||||||
|
))
|
||||||
|
.build();
|
||||||
|
let div = Division::builder()
|
||||||
|
.classes(vec!["ip"])
|
||||||
|
.elements(boxed_vec![text])
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let css = Link::builder()
|
||||||
|
.rel("stylesheet")
|
||||||
|
.href("/static/css/ip.css")
|
||||||
|
.build();
|
||||||
|
BasePage::builder()
|
||||||
|
.title("Your IP address")
|
||||||
|
.head(boxed_vec![css])
|
||||||
|
.body(boxed_vec![div])
|
||||||
|
.build()
|
||||||
|
.render()
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
pub(crate) mod files;
|
pub(crate) mod files;
|
||||||
|
pub(crate) mod ip;
|
||||||
pub(crate) mod music;
|
pub(crate) mod music;
|
||||||
pub(crate) mod projects;
|
pub(crate) mod projects;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user