introduce ip based routing
This commit is contained in:
parent
47d9494e83
commit
f13954efab
@ -1,5 +1,6 @@
|
|||||||
[default]
|
[default]
|
||||||
template_dir = "static/html"
|
template_dir = "static/html"
|
||||||
|
ip_header = "Proxy-Real-IP"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
address = "127.0.0.1"
|
address = "127.0.0.1"
|
||||||
|
|||||||
23
src/main.rs
23
src/main.rs
@ -3,6 +3,16 @@
|
|||||||
use rocket::form::Form;
|
use rocket::form::Form;
|
||||||
use rocket_dyn_templates::{Template, context};
|
use rocket_dyn_templates::{Template, context};
|
||||||
use rocket::fs::FileServer;
|
use rocket::fs::FileServer;
|
||||||
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
|
|
||||||
|
fn ip_to_ipv4(ip: IpAddr) -> Option<Ipv4Addr> {
|
||||||
|
if let IpAddr::V4(v4_addr) = ip {
|
||||||
|
Some(v4_addr)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(FromForm)]
|
#[derive(FromForm)]
|
||||||
struct LoginData {
|
struct LoginData {
|
||||||
@ -25,8 +35,17 @@ fn login(login_data: Form<LoginData>) -> Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> Template {
|
fn index(ip: IpAddr) -> Template {
|
||||||
Template::render("index", context! {})
|
if let Some(ipv4) = ip_to_ipv4(ip) {
|
||||||
|
if ipv4.is_private() {
|
||||||
|
Template::render("private_index", context! {})
|
||||||
|
} else {
|
||||||
|
Template::render("index", context! {})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Template::render("index", context! {})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
|
|||||||
49
static/html/private_index.html.tera
Normal file
49
static/html/private_index.html.tera
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user